Advertisement
Guest User

Untitled

a guest
May 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. function rmDumps(__collection, groupDoc, force = 0) {
  2. if (!force) {
  3. pivot = 0;
  4. } else {
  5. pivot = 1
  6. }
  7. db.getCollection(__collection).aggregate([
  8. {
  9. $group: { _id: groupDoc, count: { $sum: 1 }, dups: { $addToSet: '$_id' } }
  10. },
  11. {
  12. $match: { count: { $gt: pivot } }
  13. }
  14. ]).forEach(function (doc) {
  15. doc.dups.shift();
  16. if (!force) {
  17. printjson(doc)
  18. } else {
  19. db.getCollection(__collection).remove({ _id: { $in: doc.dups } });
  20.  
  21. }
  22. })
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement