Mongodb Certified Developer Associate C100dev · Free Practice Question Easy
Question 25
Can you perform the following operation in MongoDB?
- db.users.insertOne({})
-
A
Yes, it will only insert a document with an
_idfield (auto-generated). -
B
No, it will throw an error.
-
C
Yes, it will only insert a document with an
_indexfield (auto-generated). -
D
Yes, it will only insert a document without any fields.
Reveal correct answer
Correct answer: A
A.
This option is correct. Executing db.users.insertOne({}) will insert a document with an automatically generated _id field. The inserted document will not have any other fields.
B.
This option is incorrect because executing db.users.insertOne({}) will not throw an error. It is a valid command that will insert a document with an auto-generated _id field.
C.
There is no _index field in MongoDB. The auto-generated field is called _id, which uniquely identifies each document in a collection.
D.
Executing db.users.insertOne({}) will insert a document with an automatically generated _id field. Although the inserted document will not have any explicitly provided fields, it will still have the _id field.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
