Skip to content

Instantly share code, notes, and snippets.

@bjarneo
Last active June 11, 2019 06:44
Show Gist options
  • Save bjarneo/8ced7a24512be82d9fe9d2adf3f6a9a7 to your computer and use it in GitHub Desktop.
Save bjarneo/8ced7a24512be82d9fe9d2adf3f6a9a7 to your computer and use it in GitHub Desktop.
MongoDB
// find date GTE and LT
db.collection.find({createdAt: { $gte: ISODate("2019-04-10T00:00:00Z"), $lt: ISODate("2019-05-10T00:00:00Z") }}).count()
// find and sorted with limit
db.collection.find().sort({_id: -1}).limit(1).pretty()
// Remove from array
db.studios.find().toArray().map(item => item._id).forEach(id => db.studios.update({_id: id}, { $pull: { modules: { type: "commentsModule" } } }));
// Update one property
db.collection.update({ _id: ObjectId("123") }, { $set: { something: 'something' } });
// Update all documents
db.collection.updateMany({}, { $set: { something: 'somethang' } });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment