Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-15965

[Server] Allow wildcard indexes to be compounded with preceding fields

      Original Downstream Change Summary

      Enable users to create compound wildcard indexes(CWI) like

      {region: 1, …, "attributes.$**": 1}

      which combines a wildcard field with regular fields.

      Please see more details here https://jira.mongodb.org/browse/PM-1646 and the scope doc: https://docs.google.com/document/d/1Njw8ZzyapcUMqZNUUpaSyAqBJx2wxKlNoibAN4Fq5v0/edit#heading=h.sye21yee6q34

      Description of Linked Ticket

      Wildcard Indexes currently do not support compounding in any fashion. Given the way they are implemented, it seems logical that no additional compound field should follow the wildcard part. However, a preceding compound field should not violate the premises of wildcard indexing and 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.

            Assignee:
            dave.cuthbert@mongodb.com Dave Cuthbert (Inactive)
            Reporter:
            backlog-server-pm Backlog - Core Eng Program Management Team
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              1 year, 5 weeks, 4 days ago