[SERVER-10679] dropDups option for ensureIndex method's option doesn't treat number one as a truthy value. Created: 04/Sep/13  Updated: 10/Dec/14  Resolved: 04/Sep/13

Status: Closed
Project: Core Server
Component/s: Admin
Affects Version/s: 2.4.6
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Yoshiki Shibukawa Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-769 Validate top-level & index spec field... Closed
Backwards Compatibility: Minor Change
Steps To Reproduce:

$ mongo
MongoDB shell version: 2.4.6
of files is 256, should be at least 1000
> db.foo.insert({'key':1});
>[db.foo.insert({'key':1});
> db.foo.ensureIndex({key:1}, {unique:1, dropDups:1});
{
	"err" : "E11000 duplicate key error index: test.foo.$key_1  dup key: { : null }",
	"code" : 11000,
	"n" : 0,
	"connectionId" : 23,
	"ok" : 1
}
> 

Participants:

 Description   

ensureIndex treats number one for unique key (

{unique: 1}

) as a truthy value, but for dropDups key, number one (

{dropDups: 1}

) is invalid. dropDups only accept 'true'.



 Comments   
Comment by J Rassi [ 04/Sep/13 ]

This affects the server, not the shell (the shell doesn't examine the index options passed to it) – updated title accordingly.

{unique: <integer>} is an unsupported index option, and the fact that it can be used is arguably a bug. See http://docs.mongodb.org/manual/reference/method/db.collection.ensureIndex/ for documentation on what types to use with the various available index options (as such, the option combination {unique: true, dropDups: true} is the only correct way to force a unique index build). A future release of the server may reject invalid index options – see SERVER-769.

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