Is there any difference between using the field ID or _ID from a MongoDB document?
I am asking this, because I usually use “_id”, however I saw this sort({id:-1}) in the documentation: http://www.mongodb.org/display/DOCS/Optimizing+Object+IDs#OptimizingObjectIDs-Sortbyidtosortbyinsertiontime
EDIT
Turns out the docs were wrong.
I expect it’s just a typo in the documentation. The
_idfield is primary key for every document. It’s called_idand is also accessible viaid. Attempting to use anidkey may result in aillegal ObjectId formaterror.That section is just indicating that the automatically generated ObjectIDs start with a timestamp so it’s possible to sort your documents automatically. This is pretty cool since the
_idis automatically indexed in every collection. See http://www.mongodb.org/display/DOCS/Object+IDs for more information. Specifically under “BSON ObjectID Specification”.