We see in one of our services that certain queries always result in a COLLSCAN
, instead of the appropriate index being used. The data has the form
{_id: DocumentID, "field": {"child": "Cross-App-ID"}}
with an Index {"field.child":1}
.
Running the query for "field.child", i.e. db.collection.find({"field.child":"CA-ID"})
works as expected with the index being used. However, for some reason the app accessing the database creates the queries as db.collection.find({"field":{"child":"CA-ID"}})
, which results in a COLLSCAN
instead of an IXSCAN
.
2 questions for me from this:
- Shouldn't these queries be equivalent and thus treated the same?
- How can I create an index for the second use-case? All examples I found create the index like we already did.