Skip to content

Instantly share code, notes, and snippets.

@bjarneo
Last active February 2, 2016 14:40
Show Gist options
  • Save bjarneo/9024f271a2c98fda3c38 to your computer and use it in GitHub Desktop.
Save bjarneo/9024f271a2c98fda3c38 to your computer and use it in GitHub Desktop.
MongoDB
// Remove N documents from collection
var idsToRemove = db.collection.find({ "query": "to perform" }).limit(10000).sort({ "_id": -1 }).toArray().map(function(doc) { return doc._id; });
db.collection.remove({ "_id": { $in: idsToRemove }})
// Update
db.collection.update({ "_id": { $set: { "test": "update" } } });
// Get current operations
db.currentOp();
// Count shortcurt
db.collection.count({ "name": "woop" });
// Sort by natural order
db.collection.find({}).limit(10).sort({ $natural: -1 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment