MongoDB Documentation, Release 3.0.4 To create a collection _foo and insert the { a : 1 } document, use the following operation: db.getCollection("_foo").insert( { a : 1 } ) To perform a query, use the find() method, in as the following: db.getCollection("_foo").find() MongoDB cursors can return the same document more than once in some situations. 10 You can use the snapshot() method on a cursor to isolate the operation for a very specific case. snapshot() traverses the index on the _id field and guarantees that the query will return each document (with respect to the value of the _id field) no more than once. 11 The snapshot() does not guarantee that the data returned by the query will reflect a single moment in time nor does it provide isolation from insert or delete operations. As an alternative, if your collection has a field or fields that are never modified, you can use a unique index on this field or these fields to achieve a similar result as the snapshot() . Query with hint() to explicitly force the query to use that index. When modeling data in MongoDB (page 145), embedding is frequently the choice for: You should also consider embedding for performance reasons if you have a collection with a large number of small documents. Nevertheless, if small, separate documents represent the natural model for the data, then you should maintain that model. If, however, you can group these small documents by some logical relationship and you frequently retrieve the doc- uments by this grouping, you might consider “rolling-up” the small documents into larger documents that contain an array of embedded documents. Keep in mind that if you often only need to retrieve a subset of the documents within the group, then “rolling-up” the documents may not provide better performance. “Rolling up” these small documents into logical groupings means that queries to retrieve a group of documents involve sequential reads and fewer random disk accesses. Additionally, “rolling up” documents and moving common fields to the larger document benefit the index on these fields. There would be fewer copies of the common fields and there would be fewer associated key entries in the corresponding index. See Index Concepts (page 486) for more information on indexes. • “contains” relationships between entities. • one-to-many relationships when the “many” objects always appear with or are viewed in the context of their parents. 11.2.18 When should I embed documents within other documents? 11.2.17 How do I isolate cursors from intervening write operations? Warning: • You cannot use snapshot() with sharded collections . • You cannot use snapshot() with sort() or hint() cursor methods. 10 As a cursor returns documents other operations may interleave with the query: if some of these operations are updates (page 73) that cause the document to move (in the case of a table scan, caused by document growth) or that change the indexed field on the index used by the query; then the cursor will return the same document more than once. 11 MongoDB does not permit changes to the value of the _id field; it is not possible for a cursor that transverses this index to pass the same document more than once. Chapter 11. Frequently Asked Questions 754