[SERVER-11374] Can create indexes on non-insertable fields (i.e. beginning with '$') Created: 25/Oct/13  Updated: 14/May/14  Resolved: 12/Nov/13

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: 2.5.4

Type: Bug Priority: Minor - P4
Reporter: Amalia Hawkins Assignee: Amalia Hawkins
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-10075 Should forbid illegal form of TTL ind... Closed
is related to SERVER-11064 Stricter validation of index key patt... Closed
is related to SERVER-12070 Validate all indexes for new restrict... Closed
is related to SERVER-11812 Can create indexes on invalid fields ... Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Steps To Reproduce:

> coll.ensureIndex({'x.$a':1})

Participants:

 Description   

Can create indices, for example:

> coll.ensureIndex({'x.$a':1})
> coll.getIndexes()
[
	{
		"v" : 1,
		"name" : "_id_",
		"ns" : "test.t",
		"key" : {
			"_id" : 1
		}
	},
	{
		"v" : 1,
		"ns" : "test.t",
		"key" : {
			"x.$a" : 1
		},
		"name" : "x.$a_1"
	}
]

You can also create an index that contains an empty field name, i.e.: "x..a"

As you cannot save/insert/upsert a field with that name, it seems like incorrect behavior to be able to index on it.



 Comments   
Comment by auto [ 12/Nov/13 ]

Author:

{u'username': u'milkie', u'name': u'Eric Milkie', u'email': u'milkie@10gen.com'}

Message: Merge pull request #542 from hawka/server-11374b

SERVER-11374: fixing text index compatibility
Branch: master
https://github.com/mongodb/mongo/commit/a1c04c3377a3d9b9a586db49b868bbd57d2c8201

Comment by auto [ 12/Nov/13 ]

Author:

{u'username': u'hawka', u'name': u'Amalia Hawkins', u'email': u'amalia.hawkins@mongodb.com'}

Message: SERVER-11374: fixing text index compatibility
Branch: master
https://github.com/mongodb/mongo/commit/4a3c57f5d2e5295cd4d93609b06743f6f153405b

Comment by Scott Hernandez (Inactive) [ 12/Nov/13 ]

We need to note that this is breaking as some people might have "bad" code creating these indexes without problem and with this code change it will break.

If you migrate the first chunk to a server with this code, from one having the index already, it will cause the move to fail when trying to create the index. There may be more cases like this, for example, initial sync/replication. We may want to consider if this comes from replication/sharding (system init'd ops) we should not enforce these kinds of constraints.

Comment by auto [ 12/Nov/13 ]

Author:

{u'username': u'hawka', u'name': u'Amalia Hawkins', u'email': u'amalia.hawkins@mongodb.com'}

Message: SERVER-11374: Disallow creation of indexes on non-insertable fields

Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Branch: master
https://github.com/mongodb/mongo/commit/2c0c5469ed59701a6c5ac676eab019cf56267b2e

Generated at Thu Feb 08 03:25:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.