possible small bug in ensureIndex

11 views
Skip to first unread message

Raxit Sheth

unread,
Nov 19, 2012, 8:00:07 PM11/19/12
to mongod...@googlegroups.com
Hi


when one is re-applying (read as updating) index, some checks are missing.

when one have index on field a, if one is trying to update index
on field a with unique:true (and collections have duplicate) it is not
giving any error.
<neither telling, it is not executing this>

Same thing for unique:true, dropDups:true

Below is sample which will help in reproducing


> db.mytest.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "gmap3.mytest",
"name" : "_id_"
}
]
> db.mytest.find()
> db.mytest.insert({a:1})
> db.mytest.insert({a:2})
> db.mytest.insert({a:1})
> db.mytest.ensureIndex({a:1},{unique:true})
E11000 duplicate key error index: gmap3.mytest.$a_1 dup key: { : 1.0 }
> db.mytest.ensureIndex({a:1})
> db.mytest.ensureIndex({a:1},{unique:true}) <---This should give error or executed?, it is just ignoring without any notification.
> db.mytest.find()
{ "_id" : ObjectId("50aad39494cac58b7c80bb57"), "a" : 1 }
{ "_id" : ObjectId("50aad39994cac58b7c80bb58"), "a" : 2 }
{ "_id" : ObjectId("50aad39c94cac58b7c80bb59"), "a" : 1 }
> db.mytest.ensureIndex({a:1},{unique:true,dropDups:true}) <---This should give either error or executed?
> db.mytest.find()
{ "_id" : ObjectId("50aad39494cac58b7c80bb57"), "a" : 1 }
{ "_id" : ObjectId("50aad39994cac58b7c80bb58"), "a" : 2 }
{ "_id" : ObjectId("50aad39c94cac58b7c80bb59"), "a" : 1 }
> db.mytest.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "gmap3.mytest",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"a" : 1
},
"ns" : "gmap3.mytest",
"name" : "a_1"
}
]
>

Scott Hernandez

unread,
Nov 19, 2012, 8:26:53 PM11/19/12
to mongod...@googlegroups.com
Yes, there is a jira issue already: https://jira.mongodb.org/browse/SERVER-2618

Please feel free to vote and watch the issue. It is currently
scheduled for the next release.
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
Reply all
Reply to author
Forward
0 new messages