MongoDB – What about Decimal type of value?

If you want an exact representation for financial purposes, then doubles or floating point values are unsuitable as the fractional parts are subject to rounding error. Certain decimal values cannot not be represented using binary-based floating points and must be approximated. For a less technical intro, see The trouble with rounding floating point numbers; if … Read more

Date query with ISODate in mongodb doesn’t seem to work

Although $date is a part of MongoDB Extended JSON and that’s what you get as default with mongoexport, I don’t think you can really use it as a part of the query. If try exact search with $date like below: db.foo.find({dt: {“$date”: “2012-01-01T15:00:00.000Z”}}) you’ll get the error: error: { “$err” : “invalid operator: $date”, “code” … Read more

How to query nested objects?

db.messages.find( { headers : { From: “reservations@marriott.com” } } ) This queries for documents where headers equals { From: … }, i.e. contains no other fields. db.messages.find( { ‘headers.From’: “reservations@marriott.com” } ) This only looks at the headers.From field, not affected by other fields contained in, or missing from, headers. Dot-notation docs