Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Wang jason-w

  • https://www.truevault.com
  • San Francisco, CA
View GitHub Profile
@jason-w
jason-w / gist:4973476
Created Feb 17, 2013
Convert document field type in MongoDB.
View gist:4973476
// list of $type values: http://docs.mongodb.org/manual/reference/operator/type/
db.person.find( { 'integer_id' : { $type : 2 } } ).forEach( function (x) {
x.integer_id = new NumberLong(x.integer_id); // convert field to Long
db.person.save(x);
});
@jason-w
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,[])
#helper.py
def mongo_to_dict(obj, exclude_fields):
You can’t perform that action at this time.