ensureIndex for a unique index when there's already a non-unique one

45 views
Skip to first unread message

Daniel Doubrovkine

unread,
Oct 10, 2012, 10:10:34 AM10/10/12
to mongod...@googlegroups.com
I'm trying to create a unique index for where there's already an index on the field without the unique option. That fails silently (at least on MongoDB 2.0.4). I would expect it to either add an index, change the existing one to a unique one or fail with an error, no? Is this buy design?

> db.users.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "gravity-staging.users",
"name" : "_id_"
}
]
> db.users.ensureIndex({ email: 1})
> db.users.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "gravity-staging.users",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"email" : 1
},
"ns" : "gravity-staging.users",
"name" : "email_1"
}
]
> db.users.ensureIndex({ email: 1}, { unique: true })
> db.users.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "gravity-staging.users",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"email" : 1
},
"ns" : "gravity-staging.users",
"name" : "email_1"
}
]

Thanks,
dB.

--

dB. | Moscow - Geneva - Seattle - New York
dblock.org - @dblockdotorg


Andre de Frere

unread,
Oct 11, 2012, 1:36:22 AM10/11/12
to mongod...@googlegroups.com
Hi,

This is indeed a problem, and there is an open bug for it at SERVER-2618.  Please make sure you cast your vote on the Jira ticket if this issue is causing you problems.  This helps us prioritise the issue.  In this case, the fix is currently targeted at the 2.3 release schedule.  You can also watch the Jira ticket to be notified of updates to the ticket.

Regards,
André

Daniel Doubrovkine

unread,
Oct 13, 2012, 1:02:33 PM10/13/12
to mongod...@googlegroups.com
Thanks, voted. Added my 2c worth too :)

--
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