How to get ordered dictionaries in pymongo?

This solution above is correct for older versions of MongoDB and the pymongo driver but it no longer works with pymongo3 and MongoDB3+ You now need to add document_class=OrderedDict to the MongoClient constructor. Modifying the above answer for pymongo3 compatibility. from collections import OrderedDict from pymongo import MongoClient import bson client = MongoClient(document_class=OrderedDict) sample_db = … 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