Skip to content

Instantly share code, notes, and snippets.

@nainglinaung
Created June 15, 2017 11:10
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 nainglinaung/c27850af99ecc0ee12678a598f1372dc to your computer and use it in GitHub Desktop.
Save nainglinaung/c27850af99ecc0ee12678a598f1372dc to your computer and use it in GitHub Desktop.
Change type in field
var devices = db.getCollection('devices').aggregate([
{ "$group" : {_id:"$something" } }
]);
var batch = devices._batch;
for(i=0; i<=batch.length; i++) {
if (batch[i]) {
if (batch[i]._id) {
if (typeof(batch[i]._id) == 'number') {
db.devices.update({something:batch[i]._id},{$set : { something: batch[i]._id.toString() } },{multi:true})
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment