Mongodb Certified Developer Associate C100dev · Free Practice Question Medium
Question 16
What is the difference between a sparse index and a non-sparse index in MongoDB?
-
A
A sparse index indexes all documents in the collection, including those that contain the indexed field, while a non-sparse index only indexes documents that do not contain the indexed field.
-
B
A sparse index indexes all documents in the collection, including those that do not contain the indexed field, while a non-sparse index only indexes documents that contain the indexed field.
-
C
A sparse index only indexes documents that do not contain the indexed field, while a non-sparse index indexes all documents in the collection, including those that contain the indexed field.
-
D
A sparse index only indexes documents that contain the indexed field, while a non-sparse index indexes all documents in the collection, including those that do not contain the indexed field.
Reveal correct answer
Correct answer: D
A.
It's the opposite of the correct explanation. Sparse indexes only index documents that have the indexed field, while non-sparse indexes index all documents, including those that have the indexed field.
B.
It incorrectly states that sparse indexes index all documents, even those that do not have the indexed field. In reality, sparse indexes only include documents that have the indexed field.
C.
Sparse indexes are meant to include documents that have the indexed field, not exclude them. It's the non-sparse indexes that include all documents, regardless of the presence of the indexed field.
D.
In MongoDB, a sparse index is designed to only include documents that have the indexed field, excluding those that do not have the field. This helps save storage space and makes the index more efficient. On the other hand, a non-sparse index includes all documents in the collection, regardless of whether they have the indexed field or not.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
