Created
November 25, 2013 15:59
-
-
Save chanmix51/7643632 to your computer and use it in GitHub Desktop.
how to remove a subset of a mongodb collection that only has certain fields.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collection.find({"changes.objectSid": { $exists: 1}, "changes.pwdLastSet": { $exists: 1 }}).forEach(function(doc) { | |
var other_found = false; | |
for (key in doc.changes) { | |
if (key != 'objectSid' && key != 'pwdLastSet') { | |
other_found = true; | |
break; | |
} | |
} | |
if (!other_found) { | |
printjson(doc); | |
db.collection.remove(doc); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment