-
Type: New Feature
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Index Maintenance
-
None
-
Query Optimization
-
Fully Compatible
-
QO 2023-04-03
Wildcard Indexes currently do not support compounding in any fashion. A preceding compound field would support additional use cases.
Consider a collection containing polymorphic documents that share a common "type" field but may otherwise contain varying content fields...
{ "_id": <ObjectId>, "type": <int>, "content": { "field1": <string>, "field2": <string> .... } }
In such cases, many queries will want to match documents based on a content field, but only within a given target type. Hence it would be preferable to create the following index:
db.coll.createIndex({ "type": 1, "content.$**": 1 })
Which is currently not permitted and will be answered with a generic "wildcard indexes do not allow compounding" error message.
MongoDB currently scales better with few large collections and few indexes than it does with many small collections and many indexes (WT-5479). Given that one of the major advantages of MongoDB is that it is schema-free, building polymorphic collections seems like the natural way to go. More flexible wildcard indexes could provide key support in this regard.