Unique, sparse index on array field - empty array behaviour different in 2.0?

180 views
Skip to first unread message

Ben Symonds

unread,
Sep 22, 2011, 12:28:54 PM9/22/11
to mongod...@googlegroups.com
What the subject line says really! Create a unique, sparse index on array field. Before, I could have two documents with empty array. Now, I can't.

With v1.8.1:

MongoDB shell version: 1.8.1
connecting to: odyssey_test
> use foo_test
switched to db foo_test
> db.users.ensureIndex({aliases:1},{sparse:true,unique:true})
> db.users.insert({name:"alice", aliases:[]})
> db.users.insert({name:"bob", aliases:[]})
> db.users.find()
{ "_id" : ObjectId("4e7b5b219521a5c75ce16608"), "name" : "alice", "aliases" : [ ] }
{ "_id" : ObjectId("4e7b5b289521a5c75ce16609"), "name" : "bob", "aliases" : [ ] }

with v2.0.0:

MongoDB shell version: 2.0.0
connecting to: test
> use foo_test
switched to db foo_test
> db.users.ensureIndex({aliases:1},{sparse:true,unique:true})
> db.users.insert({name:"alice", aliases:[]})
> db.users.insert({name:"bob", aliases:[]})
E11000 duplicate key error index: foo_test.users.$aliases_1 dup key: { : undefined }

If I instead create the index with v:0 (to force old-style, pre-v2.0 index type), I don't get the dup key error, i.e. same behaviour as 1.8 (as you would expect).

Is this intended behaviour? I don't see anything in release notes…

Thanks,

Ben

Kyle Banker

unread,
Sep 22, 2011, 12:46:47 PM9/22/11
to mongod...@googlegroups.com
Can you create a bug report at jira.mongodb.org? This seems like a bug.

Ben Symonds

unread,
Sep 22, 2011, 1:40:32 PM9/22/11
to mongod...@googlegroups.com
Sure, no problem.  Thanks for the quick response.

On 22 Sep 2011, at 17:46, Kyle Banker wrote:

Can you create a bug report at jira.mongodb.org? This seems like a bug.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/H_u2v41D_C0J.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Ben Symonds

unread,
Oct 4, 2011, 7:23:21 AM10/4/11
to mongod...@googlegroups.com
I opened a bug (https://jira.mongodb.org/browse/SERVER-3934) but yet to see any activity on it - is that normal?

Kyle Banker

unread,
Oct 4, 2011, 10:35:40 AM10/4/11
to mongod...@googlegroups.com
Yes, this is normal. Someone will eventually assign it to a release.
Reply all
Reply to author
Forward
0 new messages