Which command is used to insert a single document into a MongoDB collection?
A
db.collection.addOne() B
db.collection.insert() C
db.collection.insertOne() D
db.collection.push()
Analysis & Theory
`insertOne()` is used to insert a single document into a collection.
Which command inserts multiple documents at once?
A
db.collection.insertAll() B
db.collection.insertMany() C
db.collection.addMany() D
db.collection.insertBulk()
Analysis & Theory
`insertMany()` is used to insert an array of documents in one operation.
What will happen if you insert a document without an `_id` field?
A
It will fail B
It will prompt for confirmation C
MongoDB will automatically generate an `_id` D
The document will not be saved
Analysis & Theory
MongoDB will automatically generate a unique `_id` if it is not provided.
Which data format is used to define documents during insertion?
A
XML B
CSV C
JSON or BSON D
SQL
Analysis & Theory
Documents are written in JSON format, and MongoDB internally stores them as BSON.
What does `ordered: false` do in `insertMany()`?
A
Skips validation B
Ensures documents are inserted in reverse C
Inserts all documents even if some fail D
Sorts the documents before inserting
Analysis & Theory
`ordered: false` allows MongoDB to continue inserting the remaining documents even if some fail.
Which of the following is a valid document for insertion?
A
{ 'name': 'Alice', age: 30 } B
{ name: 'Alice', 'age': 30 } C
{ 'name': 'Alice', 'age': 30 } D
{ name = 'Alice', age = 30 }
Analysis & Theory
Correct MongoDB documents use key-value pairs in JSON format with string keys in quotes.
What does `db.users.insertOne({ name: 'John', age: 25 })` do?
A
Adds multiple users B
Inserts one document into the 'users' collection C
Creates a new collection named 'John' D
Deletes the user named 'John'
Analysis & Theory
It inserts a single document into the `users` collection.
If you try to insert a document with a duplicate `_id`, what happens?
A
It silently updates the document B
The duplicate is ignored C
An error is thrown D
MongoDB renames the `_id`
Analysis & Theory
MongoDB does not allow duplicate `_id` values. An error will be thrown.
Which command checks the number of documents inserted by `insertMany()`?
A
result.count() B
result.total() C
result.insertedCount D
result.numInserted()
Analysis & Theory
`insertedCount` tells how many documents were successfully inserted.
Can you insert nested documents in MongoDB?
A
No, only flat key-value pairs are allowed B
Yes, but only using insertMany() C
Yes, MongoDB supports nested (embedded) documents D
Only for certain fields like `_id`
Analysis & Theory
MongoDB fully supports nested (embedded) documents inside a main document.