MongoDB Documentation, Release 3.0.4 Think of the _id field as the primary key for a collection. Every document must have a unique _id field. You may store any unique value in the _id field. The default value of _id is an ObjectId which is generated when the client inserts the document. An ObjectId is a 12-byte unique identifier suitable for use as the value of an _id field. Note: In sharded clusters , if you do not use the _id field as the shard key , then your application must ensure the uniqueness of the values in the _id field to prevent errors. This is most-often done by using a standard auto-generated ObjectId . Before version 2.2, capped collections did not have an _id field. In version 2.2 and newer, capped collections do have an _id field, except those in the local database . See Capped Collections Recommendations and Restrictions (page 209) for more information. Indexes on Embedded Fields You can create indexes on fields within embedded documents, just as you can index top-level fields in documents. Indexes on embedded fields differ from indexes on embedded documents (page 488), which include the full content up to the maximum index size of the embedded document in the index. Instead, indexes on embedded fields allow you to use a “dot notation,” to introspect into embedded documents. Consider a collection named people that holds documents that resemble the following example document: You can create an index on the address.zipcode field, using the following specification: db.people.createIndex( { "address.zipcode": 1 } ) Indexes on Embedded Documents You can also create indexes on embedded documents. For example, the factories collection contains documents that contain a metro field, such as: The metro field is an embedded document, containing the embedded fields city and state . The following com- mand creates an index on the metro field as a whole: db.factories.createIndex( { metro: 1 } ) The following query can use the index on the metro field: db.factories.find( { metro: { city: "New York", state: "NY" } } ) This query returns the above document. When performing equality matches on embedded documents, field order matters and the embedded documents must match exactly. For example, the following query does not match the above document: Chapter 8. Indexes 488 { _id: ObjectId(...), metro: { city: "New York", state: "NY" }, name: "Giant Factory" } {"_id": ObjectId(...), "name": "John Doe", "address": { "street": "Main", "zipcode": "53511", "state": "WI" } }