Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rmDumps(__collection, groupDoc, force = 0) {
- if (!force) {
- pivot = 0;
- } else {
- pivot = 1
- }
- db.getCollection(__collection).aggregate([
- {
- $group: { _id: groupDoc, count: { $sum: 1 }, dups: { $addToSet: '$_id' } }
- },
- {
- $match: { count: { $gt: pivot } }
- }
- ]).forEach(function (doc) {
- doc.dups.shift();
- if (!force) {
- printjson(doc)
- } else {
- db.getCollection(__collection).remove({ _id: { $in: doc.dups } });
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement