MongoDB aggregate and functions

Hello
I have basic code to delete duplicates from collection in mongodb

db.myCollection.aggregate([
 {
        "$group": {
            "_id": {"key": "$key"},
            "dups": {"$push": "$_id"},
            "count": { "$sum": 1 }
        }
    },
    {
         "$match": {
             "count": { "$gt": 1 }
         }
     }
    ]).forEach(function(doc){
        doc.dups.shift();
        db.myCollection.remove({
            "_id" : {"$in": doc.dups}
        });
    })

But how all of this execute using library mgo?

I’ve see examples with Pipe (for sorting and grouping) but how use “forEach” function in mgo
Did someone execute something like this?
Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.