var count=0;
var coll = [];
db.getCollection('some_collection').aggregate([
{ "$group": {
"_id": { "id": "$id" },
"dups": { "$push": "$_id" },
"count": { "$sum": 1 }
}},
{ "$match": { "count": { "$gt": 1 } }}
],
{"allowDiskUse": true}).map(function(record, index){
count++;
coll.push(record.dups[0]);
});
printjson(coll);
// db.getCollection('coins_tweets_stream').remove({_id:{$in:coll}})
Faster than aggregate!
db.getCollection('some-collection').find({}).sort({"id":-1}).limit(1)
db.getCollection('collection').createIndex( { "id": 1 }, { unique: true } )