what is difference between _id : "..." and _id : {"$oid" : "..."}

5,590 views
Skip to first unread message

tunggad

unread,
Jun 21, 2011, 6:40:34 PM6/21/11
to mongodb-user
All the time i nearly only see examples (official wikis) with the
field _id : "...", but my documents, inserted by Java Driver version
2.6.2 on MongoDB 1.8.1, windows, they all have the field _id :
{"$oid" : "..."}.

It may be a very simple thing, but i could not find explanation/info
about it anywhere. Could you pls tell me what's the difference?

Ken Egozi

unread,
Jun 21, 2011, 6:44:11 PM6/21/11
to mongod...@googlegroups.com
it is just a different serialization format, started with the newer shells, it clearly states that the type of the id is the 12bit object-id and not some other, arbitrary string


Ken Egozi.
http://www.kenegozi.com/blog
http://www.delver.com
http://www.musicglue.com
http://www.castleproject.org
http://www.idcc.co.il - הכנס הקהילתי הראשון למפתחי דוטנט - בואו בהמוניכם



--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Scott Hernandez

unread,
Jun 21, 2011, 10:09:31 PM6/21/11
to mongod...@googlegroups.com
It isn't a shell thing but an extended json format. The java driver
prints out, toString() returns, the extended json format so you can
read it, and know what is there. This is primarily because json
doesn't have support for many of the bson types which are used in
mongodb. http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON

tunggad

unread,
Jun 22, 2011, 3:59:25 AM6/22/11
to mongodb-user
ok, thank you.

So, if i want to look up a document by id, how must the query document
look like:
{_id : "..."} or {_id : {"$oid" : "..."}} ?
Reply all
Reply to author
Forward
0 new messages