Skip to content

Instantly share code, notes, and snippets.

@jason-w
Created February 17, 2013 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jason-w/4973476 to your computer and use it in GitHub Desktop.
Save jason-w/4973476 to your computer and use it in GitHub Desktop.
Convert document field type in MongoDB.
// 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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment