Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-48570

Allow wildcard indexes to be compounded with preceding fields

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Index Maintenance
    • Labels:
      None

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            backlog-query-optimization Backlog - Query Optimization
            Reporter:
            ralf.strobel Ralf Strobel
            Participants:
            Votes:
            10 Vote for this issue
            Watchers:
            20 Start watching this issue

              Dates

              Created:
              Updated: