Created
October 19, 2015 11:45
-
-
Save gitfvb/cd4907a19b5e2c1f6e33 to your computer and use it in GitHub Desktop.
remove the 1000 first entries of the mongodb collection 'foo' by id
This file contains 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
// count all the records first | |
db.getCollection('foo').find({}).count(); | |
// save the the first 1000 entries ids to an array | |
removeIdsArray = db.getCollection('foo').find({}) | |
.limit(1000) | |
.toArray() | |
.map(function(doc) { return doc._id; }); | |
// remove them by going through that array | |
db.getCollection('foo').remove({_id: {$in: removeIdsArray}}); | |
// count the records again | |
db.getCollection('foo').find({}).count(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment