Skip to content

Instantly share code, notes, and snippets.

@nainglinaung
Created June 15, 2017 11:10
Show Gist options
  • Save nainglinaung/c27850af99ecc0ee12678a598f1372dc to your computer and use it in GitHub Desktop.
Save nainglinaung/c27850af99ecc0ee12678a598f1372dc to your computer and use it in GitHub Desktop.

Revisions

  1. nainglinaung created this gist Jun 15, 2017.
    16 changes: 16 additions & 0 deletions aggrate.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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})
    }
    }
    }

    }