-
Type: Bug
-
Resolution: Unresolved
-
Priority: 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.
- related to
-
SERVER-89210 Chunk migration can unnecessarily fail due to inconsistency between listIndexes and local catalog
- Open
-
SERVER-73442 The type of the "bits" field can differ between createIndexes and listIndexes
- Backlog
-
SERVER-55863 createIndexes permits some text index-only options for non-text indexes
- Closed
-
SERVER-49224 Improve validation of index spec fields
- Closed
-
SERVER-90768 Compare output between listCollections and $listCatalog for the same database and verify equivalence in testing
- Closed