Raxit Sheth
unread,Nov 19, 2012, 8:00:07 PM11/19/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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"
}
]
>