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

Validate in createIndex that options for 2dsphere, text, etc. indexes are only used with matching index types

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 5.0.0, 6.0.0, 7.0.0, 8.1.0-rc0, 8.0.0
    • Component/s: None
    • None
    • Storage Execution
    • ALL

      Various options which are intended for index types such as 2d, 2dsphere, text. etc. are accepted in as inputs by db.collection.createIndex for any kind of index, such as basic B-Tree indexes. For example, the following command works:

      > db.coll.createIndex({x:1}, {
            textIndexVersion: 3,
            '2dsphereIndexVersion': 3,
            bits: 26,
            min: -180,
            max: 180,
         })
      x_1
      

       

      The index options do not appear in db.collection.getIndexes output, as they are filtered out according to the list in list_indexes_allowed_fields.h, however, they are persisted in the catalog and can be seen in various ways, such as the $indexStats or $listCatalog aggregation stages:

      test> db.coll.aggregate([{$indexStats:{}},{$match:{name:'x_1'}}])
      [
        {
          name: 'x_1',
          key: { x: 1 },
          host: 'b00f7d9b52d6:27017',
          accesses: { ops: Long('0'), since: ISODate('2024-11-13T16:11:31.607Z') },
          spec: {
            v: 2,
            key: { x: 1 },
            name: 'x_1',
            textIndexVersion: 3,
            '2dsphereIndexVersion': 3,
            bits: 26,
            min: -180,
            max: 180
          }
        }
      ]
      

      Passing options intended for specific index types for other kinds of indexes should be disallowed by db.collection.createIndex. This behavior would be consistent with the behavior of other index options:

      > db.coll.createIndex({ x: 1 }, { wildcardProjection: "whatever" })
      MongoServerError[BadValue]: Error in specification { wildcardProjection: "whatever", name: "x_1", key: { x: 1 } } :: caused by :: The field 'wildcardProjection' is only allowed in an 'wildcard' index
      

      In general, incongruent index options are known to be problematic (see related issues). In the specific case of this issue, it should be noted that the index options will not be cloned upon initial sync (as they don't appear in listIndexes' output) which may lead to inconsistent index between replica set members but at the moment this has not been observed to lead to any broader issue.

            Assignee:
            Unassigned Unassigned
            Reporter:
            joan.bruguera-mico@mongodb.com Joan Bruguera Micó
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: