16

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?

Kumar Manish
  • 1,166
  • 1
  • 16
  • 28
  • FYI for anyone who is trying to get plain JSON (e.g. `{"$oid": x}` instead of `ObjectId(x)` from the `mongo` command line client: try using `mongoexport` instead. – rakslice Feb 06 '15 at 21:02

1 Answers1

17

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).
Sammaye
  • 43,242
  • 7
  • 104
  • 146
  • So it is not related to any driver version etc ? It actually figures, because in 'prod' we use a tool to look at the data, where as in "qa" we use the command line to look at the data inserted. – Kumar Manish Sep 26 '12 at 13:18
  • @KumarManish nah all driver versions should be consistent on this front, yea the tool is just grabbing the data out in full plain format (or even translating it on their end to make it look like that) whereas the console translates all the objects in your doc. – Sammaye Sep 26 '12 at 13:51
  • I just verified with someone logging in manually to the production database and I did see that the qa & prod versions were shown exactly the same. – Kumar Manish Sep 30 '12 at 06:12
  • I actually found the case where 2 objects in the same environment with the same driver returning 2 different values with the same version of Java driver (3.3.0) on the same machine. Now my app is failing because of it. http://stackoverflow.com/questions/39603179/excluding-fields-when-retrieving-document-from-mongodb – juminoz Sep 21 '16 at 14:35