Last active
June 11, 2019 06:44
-
-
Save bjarneo/8ced7a24512be82d9fe9d2adf3f6a9a7 to your computer and use it in GitHub Desktop.
MongoDB
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
// 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