Difference between _id & $oid ; $date & IsoDate in mongo database

Kumar Manish picture Kumar Manish · Sep 26, 2012 · Viewed 7.8k times · Source

We are using mongo db to store certain records in production database.

We see our records having "_id" : { "$oid" : "50585fbcb046b2709a534502"} in production database , while we see same record as "_id" : ObjectId(" 50585fbcb046b2709a534502 ") in the qa database. For dates we see "ld" : { "$date" : "2011-12-03T17:00:00Z"} in prod database, while "ld" :ISODate("2011-12-03T17:00:00Z") in qa database. We have tested our queries successfully in qa environment, but worried it might fail in production

1) Will my java queries work seamlessly on prod & qa both? (I am using morphia apis to query) 2) Are they internally being stored in the same identical way?

Answer

Sammaye picture Sammaye · Sep 26, 2012

To answer the two questions:

  1. Yes they will
  2. Yes they are the same, it is merely the representation within the item you are looking in (console or app) as to how they display. Console (later versions anyway, about 1.4+) will display ObjectId and ISODate (normally) whereas picking it out directly from the server language (Java in your case) will tend to show the full objects properties ($oid and $date in this case).