MongoDB is a popular database that stores data JSON-like documents.
It offering high performance, scalability, and easy of use for modern application development.
1. find()-
db.abc.find()Find all documents in the "abc" collection
db.abc.find({ age: { $gt: 30 } })Find documents where collection age is greater than 30.
2.findOne()-
db.abc.findOne()Find the first document in the "abc" collection
3. insertOne()-
db.abc.insertOne({ username: "Tutorials_on_web", email: "info@tutorialsonweb.com", age: 25 })Insert a new document into the "abc" collection
4. insertMany():
db.abc.insertMany([
{ username: "mahendra", email: "mahendra@tutorialsonweb.com", age: 30 },
{ username: "lokendra", email: "lokendra@tutorialsonweb.com", age: 35 }
])Insert multiple documents into the "abc" collection.
5. updateOne()-
db.abc.updateOne({ username: "tutorials_on_web" }, { $set: { age: 31 } })Update a document in the "abc" collection set age 31 where username is “tutorials_on_web”
6. updateMany()-
db.abc.updateMany({ status: "inactive" }, { $set: { status: "active" } })Update multiple documents in the "abc" collection which records status is inactive.
7. deleteOne()-
db.abc.deleteOne({ username: "tutorials_on_web" })Delete a document from the "abc" collection where username is tutorials_on_web
8. deleteMany()-
db.abc.deleteMany({ age: { $gte: 40 } })Delete multiple documents from the "abc" collection where age is grater then 40.