Complete the code to insert a single document into the collection.
db.collection.[1]({ name: "Alice", age: 25 })
The insertOne method inserts a single document into the collection.
Complete the code to insert a document and handle the returned promise.
db.collection.insertOne({ item: "book", qty: 10 }).[1](result => console.log(result.insertedId))The then method handles the promise when the insertion succeeds.
Fix the error in the code to correctly insert a document.
db.collection.insertOne({ name: "Bob", age: 30 [1] )The document object must be closed with a curly brace } before the closing parenthesis.
Fill both blanks to insert a document and print the inserted ID.
db.collection.[1]({ name: "Eve", active: true }).[2](res => console.log(res.insertedId))
Use insertOne to add one document and then to handle the success.
Fill all three blanks to insert a document, handle success, and catch errors.
db.collection.[1]({ username: "john_doe" }).[2](res => console.log(res.insertedId)).[3](err => console.error(err))
Use insertOne to insert, then to handle success, and catch to handle errors.
