db.ip_info.aggregate([
{'$group':{'_id':'$query','num':{'$sum':1},'dups':{'$addToSet':'$_id'}}},
{'$match':{'num':{'$gte':2}}},
{'$sort':{'_id':1}},
],{allowDiskUse:true}).forEach(function(doc){
doc.dups.shift();
db.ip_info.remove({'_id':{'$in':doc.dups}});
})



