db.集合.aggregate([ { $group: { _id: {字段1: '$字段1',字段2: '$字段2'},count: {$sum: 1},dups: {$addToSet: '$_id'}} }, { $match: {count: {$gt: 1}} } ]).forEach(function(doc){ doc.dups.shift(); db.集合.remove({_id: {$in: doc.dups}}); })
db.order_warning_info.aggregate([{$match:{"iotprofile" : "通用磨坊测试"}}, { $group: { _id: {order_id: '$order_id',scan_time: '$scan_time'},count: {$sum: 1},dups: {$addToSet: '$_id'}} }, { $match:{count:{$gt:1}} } ]).forEach(function(doc){ doc.dups.shift(); db.order_warning_info.remove({_id: {$in: doc.dups}}); }) #$match 后面跟插叙你的条件 #group: 后面跟去重的条件 #$addToSet 以_id存储结构