Operational Defect Database

BugZero found this defect 60 days ago.

MongoDB | 2615055

Prevent user from inserting doc via applyOps with recordId that already exists

Last update date:

3/20/2024

Affected products:

MongoDB Server

Affected releases:

No affected releases provided.

Fixed releases:

No fixed releases provided.

Description:

Info

If you have documents and an index {a: 1}: // Collection: $recordId: 1 -> {_id: 1, a: 1} $recordId: 2 -> {_id: 2 a: 2} $recordId: 3 -> {_id: 3, a: 3} // {a: 1} index: {a: 1} -> $recordId: 1 {a: 2} -> $recordId: 2 {a: 3} -> $recordId: 3 Perform an insert via applyOps: db.runCommand({ applyOps: [ { "op" : "i", "ns" : "test.mycoll", "o" : { "_id" : 34, "a": 34 }, "o2" : { "_id" : 34, }, "rid": NumberLong(1) } ] }) In the collection, we end up overwriting the document. But in the index, we add a new entry! // Collection: $recordId: 1 -> {_id: 34, a: 34} $recordId: 2 -> {_id: 2 a: 2} $recordId: 3 -> {_id: 3, a: 3} // {a: 1} index: {a: 1} -> $recordId: 1 {a: 2} -> $recordId: 2 {a: 3} -> $recordId: 3 {a: 34} -> $recordId: 1 // new entry And if you delete the document with {a: 34}, you'll have a dangling index entry: // Collection: $recordId: 2 -> {_id: 2 a: 2} $recordId: 3 -> {_id: 3, a: 3} // {a: 1} index: {a: 1} -> $recordId: 1 // dangling {a: 2} -> $recordId: 2 {a: 3} -> $recordId: 3

Top User Comments


Steps to Reproduce


Additional Resources / Links

Share:

BugZero® Risk Score

What's this?

Coming soon

Status

Backlog

Learn More

Search:

...