[SERVER-12874] Ensure index does not properly update index with case mismatch Created: 24/Feb/14  Updated: 10/Dec/14  Resolved: 25/Feb/14

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

Type: Bug Priority: Minor - P4
Reporter: Michael Kennedy Assignee: J Rassi
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

Run the two lines of ensure index above and view the resulting indexes.

Participants:

 Description   

Running the following code on 2.6 rc0:

db.bug.ensureIndex({'isactive': 1}, {name: 'find_active'});
db.bug.ensureIndex({'IsActive': 1}, {name: 'find_active'});

Results in the bug collection with an index for:

{'isactive': 1}

NOT an index for

{'IsActive': 1}

My expectation is the second index would either replace or co-exist with the first. It is not that the first index is kept and the second statement is ignored.



 Comments   
Comment by J Rassi [ 25/Feb/14 ]

Not a problem, and thanks for the submission. Note that if you were not using the shell in interactive mode (i.e. you were using it to run a javascript file), then you wouldn't have seen this error without testing the return value of ensureIndex() – that could possibly explain the discrepancy. I'll close this as "Cannot reproduce".

Comment by Michael Kennedy [ 25/Feb/14 ]

Hi Jason,

Thanks for looking into this. It might be the shell I was using...

Actually, the error was just silenced. Sorry for wasting your time.

Cheers,
Michael

Comment by J Rassi [ 25/Feb/14 ]

When I reproduce this the server doesn't ignore the second statement, it produces an error since the "find_active" index already exists:

$ mongo
MongoDB shell version: 2.6.0-rc0
connecting to: test
> db.version()
2.6.0-rc0
> db.bug.ensureIndex({'isactive': 1}, {name: 'find_active'});
WriteResult({ "nInserted" : 1 })
> db.bug.ensureIndex({'IsActive': 1}, {name: 'find_active'});
WriteResult({
	"nInserted" : 0,
	"writeError" : {
		"code" : 67,
		"errmsg" : "Trying to create an index with same name find_active with different key spec { IsActive: 1.0 } vs existing spec { isactive: 1.0 }"
	}
})
> db.bug.getIndexes()
[
	{
		"v" : 1,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_",
		"ns" : "test.bug"
	},
	{
		"v" : 1,
		"key" : {
			"isactive" : 1
		},
		"name" : "find_active",
		"ns" : "test.bug"
	}
]
>

Do you not observe the above behavior?

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