Recall & Review
beginner
What does the
insertOne method do in MongoDB?The
insertOne method adds a single new document to a MongoDB collection.Click to reveal answer
beginner
How do you use
insertOne to add a document with a name and age?You call
insertOne with an object like { name: 'Alice', age: 30 } to add that document to the collection.Click to reveal answer
intermediate
What does
insertOne return after inserting a document?It returns a result object containing
insertedId, which is the unique ID of the new document.Click to reveal answer
beginner
Can
insertOne insert multiple documents at once?No,
insertOne inserts only one document. To insert many, use insertMany.Click to reveal answer
intermediate
What happens if you try to insert a document with a duplicate _id using
insertOne?MongoDB will return an error because
_id must be unique in a collection.Click to reveal answer
What is the main purpose of the
insertOne method in MongoDB?✗ Incorrect
insertOne adds exactly one new document to a MongoDB collection.
Which of these is a valid argument for
insertOne?✗ Incorrect
insertOne expects a single document object, like { name: 'Bob', age: 25 }.
What does
insertOne return after a successful insert?✗ Incorrect
It returns an object containing insertedId, the new document's unique ID.
If you want to add many documents at once, which method should you use instead of
insertOne?✗ Incorrect
insertMany is designed to add multiple documents in one call.
What error occurs if you insert a document with an existing
_id using insertOne?✗ Incorrect
MongoDB enforces unique _id values, so duplicates cause a duplicate key error.
Explain how the
insertOne method works in MongoDB and what it returns.Think about adding one item to a list and getting its ID back.
You got /3 concepts.
Describe the difference between
insertOne and insertMany.One is for single items, the other for many.
You got /3 concepts.