[SERVER-7164] Duplicate key errors are different on capped collections Created: 26/Sep/12  Updated: 06/Dec/22  Resolved: 15/Jan/16

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

Type: Bug Priority: Minor - P4
Reporter: Gustavo Niemeyer Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

Got a real bug out of this already:

> db.foo.insert({_id: 1})
duplicate key insert for unique index of capped collection

> db.bar.insert({_id: 1})
E11000 duplicate key error index: test.bar.$id dup key: { : 1.0 }



 Comments   
Comment by Kevin Pulo [ 15/Jan/16 ]

The latest stable release, MongoDB 3.2.1, does the right thing, both for WiredTiger and MMAPv1.

$ mlaunch init --single --port 11111 --binarypath /m/3.2.1/bin
launching: /m/3.2.1/bin/mongod on port 11111
$ /m/3.2.1/bin/mongo --port 11111 --norc
MongoDB shell version: 3.2.1
connecting to: 127.0.0.1:11111/test
> db.version()
3.2.1
> db.createCollection("foo", {capped: true, size: 10*1048576})
{ "ok" : 1 }
> db.foo.insert({_id:1})
WriteResult({ "nInserted" : 1 })
> db.foo.insert({_id:1})
WriteResult({
        "nInserted" : 0,
        "writeError" : {
                "code" : 11000,
                "errmsg" : "E11000 duplicate key error collection: test.foo index: _id_ dup key: { : 1.0 }"
        }
})
> db.bar.insert({_id:1})
WriteResult({ "nInserted" : 1 })
> db.bar.insert({_id:1})
WriteResult({
        "nInserted" : 0,
        "writeError" : {
                "code" : 11000,
                "errmsg" : "E11000 duplicate key error collection: test.bar index: _id_ dup key: { : 1.0 }"
        }
})

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