A collection has an indexed involved field_A
. But field_A
is not required. So what happens if some documents do not have this field? Will the index still work for documents that do have this field?
A collection has an indexed involved field_A
. But field_A
is not required. So what happens if some documents do not have this field? Will the index still work for documents that do have this field?
2
Answers
Yes , index will work for the documents that have the field available and indexed , but you may look on the options to create sparse or partial type of indices which add some additional optimisation in certain cases …
P.S.
In regular indices for documents that miss the field in the index this is seen as null value … , so if you search by field_A: null you will find those documents missing the field and those that are equal to null …
Yes it works, here is a test:
You see index
field_A_1
has a size of 20 kiByte. This behavior is different to most relational DBMS database where such index would have a size of zero.The index is also used by your query, if you use the field: