Skip to content

Instantly share code, notes, and snippets.


Jason Wang jason-w

  • San Francisco, CA
View GitHub Profile
jason-w / gist:4973476
Created Feb 17, 2013
Convert document field type in MongoDB.
View gist:4973476
// list of $type values:
db.person.find( { 'integer_id' : { $type : 2 } } ).forEach( function (x) {
x.integer_id = new NumberLong(x.integer_id); // convert field to Long;
jason-w / gist:4969476
Created Feb 17, 2013
Helper functions that converts a MongoEngine Document to a Python Dict so it can be easily converted to JSON.
View gist:4969476
class Person (db.Document):
name = db.StringField(required=True)
created_date = db.ComplexDateTimeField(default=datetime.datetime.utcnow(), required=True)
def to_dict(self):
return helper.mongo_to_dict(self,[])
def mongo_to_dict(obj, exclude_fields):
You can’t perform that action at this time.