[SERVER-4562] createIndex on array field with unique and dropDups:true gives "Invalid BSONObj size" error instead of duplicate key error if array has 2 or more duplicates Created: 26/Dec/11  Updated: 29/Feb/12  Resolved: 31/Jan/12

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 2.0.2, 2.1.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Daniel Crosta Assignee: Aaron Staple
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS X 64bit 2.0.1, 2.1.x nightly (2011-11-06 build); Linux 64bit 2.0.2


Issue Links:
Duplicate
duplicates SERVER-4770 ensureIndex with unique and dropDups ... Closed
Operating System: ALL
Participants:

 Description   

test> db.things.drop()
true
test> db.things.save({"array": [ 1, 2, 3 ]})
test> db.things.save({"array": [ 2, 3, 4 ]})
test> db.things.createIndex({array: 1}, {unique: true, dropDups: true})
Invalid BSONObj size: -286331154 (0xEEEEEEEE) first element: _id: ObjectId('4ef8fc7f7797e97e21a8c7da')

but:

test> db.things.drop()
true
test> db.things.save({"array": [ 1, 2, 3 ]})
test> db.things.save({"array": [ 2, 3, 4 ]})
test> db.things.createIndex({array: 1}, {unique: true, dropDups: 1})
E11000 duplicate key error index: test.things.$array_1  dup key: { : 3.0 }

This only seems to happen if there are 2 or more duplicates in the array; with 1 duplicate, it works correctly with either true or 1 as argument to dropDups



 Comments   
Comment by Daniel Crosta [ 26/Dec/11 ]

correct a typo in second example – verified that it still works as expected.

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