[SERVER-769] Validate top-level & index spec field names for the createIndexes command Created: 16/Mar/10  Updated: 01/Nov/19  Resolved: 23/Sep/16

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: 3.4.0-rc0

Type: New Feature Priority: Critical - P2
Reporter: Kyle Banker Assignee: James Wahlin
Resolution: Done Votes: 9
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-10679 dropDups option for ensureIndex metho... Closed
is duplicated by SERVER-11577 Check function's BSON options Closed
is duplicated by SERVER-30937 Migration failed because of `already... Closed
is duplicated by SERVER-20424 Creating Index with invalid properties Closed
is duplicated by SERVER-8638 Allowed to build {<field>:0} index Closed
is duplicated by SERVER-16995 Validate options for createIndexes co... Closed
is duplicated by SERVER-17449 collection.ensureIndex should ignore ... Closed
Related
related to SERVER-26287 createIndexes should confirm that ind... Closed
related to SERVER-27711 createIndexes command incorrectly rej... Closed
related to SERVER-36944 applyOps does not permit unknown fiel... Closed
related to SERVER-26217 Disallow dropDups field in createInde... Closed
related to DOCS-9049 3.4: Mention stricter createIndexes v... Closed
is related to SERVER-24032 When processing createIndexes (on V2 ... Closed
is related to SERVER-24033 createIndexes command should write th... Closed
is related to SERVER-11266 Error on capped collection TTL delete... Closed
is related to SERVER-30272 Found an index like {fieldName: 0} Closed
is related to SERVER-14422 Validate index option values Closed
is related to SERVER-21779 db.runCommand() should return error i... Closed
is related to DRIVERS-2109 Add tests to Index Management spec Backlog
Backwards Compatibility: Minor Change
Sprint: Integration 2016-10-10
Participants:
Case:

 Description   

Add validation for createIndexes field names both at the top level and in the index specification. This is to prevent mis-spelled field names and correct field names being placed at the wrong level of the command specification (for example "background: true" being placed at the top level rather then within the index spec document.



 Comments   
Comment by Githook User [ 23/Sep/16 ]

Author:

{u'username': u'jameswahlin', u'name': u'James Wahlin', u'email': u'james.wahlin@10gen.com'}

Message: SERVER-769 Validate createIndexes field names
Branch: master
https://github.com/mongodb/mongo/commit/5563428f99af20c29cb334f97e84f0dcc1cb102a

Comment by James Wahlin [ 23/Sep/16 ]

kevin.pulo - I created SERVER-26287 to address your TTL on capped collection concern. Please review that ticket and modify as needed.

Comment by Charlie Swanson [ 21/Jun/16 ]

Adding my two cents here: the test jstests/noPassthroughWithMongod/ttl1.js could be improved if we better validate the TTL arguments.

Comment by Kevin Pulo [ 20/Jan/16 ]

Another case is creating a TTL index on a capped collection, which is can be created but doesn't actually achieve anything productive.

> db.createCollection("test", {capped:true, size: 102400})
{ "ok" : 1 }
> db.test.ensureIndex({foo:1}, {expireAfterSeconds: 10})
{
        "createdCollectionAutomatically" : false,
        "numIndexesBefore" : 1,
        "numIndexesAfter" : 2,
        "ok" : 1
}
> db.test.insert({foo:new Date()})
WriteResult({ "nInserted" : 1 })

2016-01-19T18:17:11.210+1100 I STORAGE  [TTLMonitor] failing remove on a capped ns test.test
2016-01-19T18:17:11.210+1100 E INDEX    [TTLMonitor] Error processing ttl index: { v: 1, key: { foo: 1.0 }, name: "foo_1", ns: "test.test", expireAfterSeconds: 10.0 } -- 10089 cannot remove from a capped collection

If such indexes were disallowed in the first place, it could have avoided the effort on SERVER-11266, SERVER-16749 and SERVER-20920.

In addition, the TTL docs state that creating such an index isn't possible, which isn't strictly true until this ticket is resolved.

You cannot create a TTL index on a capped collection because MongoDB cannot remove documents from a capped collection.

Comment by Stefan Wójcik [ 03/Mar/15 ]

One more example of the same issue:

> db.notification.getIndexes()[1]
{
    "v" : 1,
    "key" : {
        "_cls" : 1,
        "membership" : 1
    },
    "ns" : "closeio.notification",
    "name" : "_cls_1_membership_1",
    "background" : false,
    "dropDups" : false
}
> db.notification.ensureIndex({ _cls: 1, membership: 1 })
{ "numIndexesBefore" : 14, "note" : "all indexes already exist", "ok" : 1 }
> db.notification.ensureIndex({ _cls: 1, membership: 1 }, { background: true })
{ "numIndexesBefore" : 14, "note" : "all indexes already exist", "ok" : 1 }
> db.notification.ensureIndex({ _cls: 1, membership: 1 }, { whatever: true })
{
    "ok" : 0,
    "errmsg" : "Index with name: _cls_1_membership_1 already exists with different options",
    "code" : 85
}
> db.notification.ensureIndex({ _cls: 1, membership: 1, whatever:1 }, { whatever: true })
{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 14,
    "numIndexesAfter" : 15,
    "ok" : 1
}
> db.notification.getIndexes()[14]
{
    "v" : 1,
    "key" : {
        "_cls" : 1,
        "membership" : 1,
        "whatever" : 1
    },
    "name" : "_cls_1_membership_1_whatever_1",
    "ns" : "closeio.notification",
    "whatever" : true
}

1. Calling ensureIndex with an unsupported option shouldn't consider the spec different from the existing one (i.e. the error shouldn't occur).
2. Options that aren't supported shouldn't be stored on the index spec.

Generated at Thu Feb 08 02:55:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.