Complete the code to find all documents in the collection.
db.users.[1]()The find() method retrieves all documents from a MongoDB collection, similar to selecting all rows from a table in SQL.
Complete the code to insert a new document into the collection.
db.products.[1]({ name: 'Pen', price: 1.5 })
The insertOne() method adds a single new document to a collection, similar to inserting a new row in a table.
Fix the error in the code to update a document's price.
db.items.updateOne({ name: 'Book' }, { [1]: { price: 12 } })The $set operator updates the value of a field in a document. Other operators like $get or $add are not valid for updates.
Fill both blanks to delete all documents where age is less than 18.
db.students.deleteMany({ age: { [1]: [2] } })The $lt operator means 'less than'. So this query deletes documents where age is less than 18.
Fill all three blanks to find documents where status is 'active' and sort by score descending.
db.players.find({ status: [1] }).sort({ [2]: [3] })The query finds documents with status 'active' and sorts them by score in descending order using -1.