Info
This is very similar to insert when possible" class="issue-link" data-issue-key="SERVER-14322">SERVER-14322 however I'm in a case where the auto retry should happen from what I understand but it does not.
Error:
E11000 duplicate key error collection: dbName.collectionName index: a_1_b_1 dup key: { a: 31910, b: "2021-09-02T00:00:00Z" }
Indexes
> db.collectionName.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "databaseName.collectionName"
},
{
"v" : 2,
"unique" : true,
"key" : {
"a" : 1,
"b" : 1
},
"name" : "a_1_b_1",
"ns" : "databaseName.collectionName",
"sparse" : true
}
]
Commands run (though ReactiveMongo Scala):
> db.collectionName.findAndModify(
query: { a: 31910, b: "2021-09-02T00:00:00Z" },
update: { $inc: { c: 1 } },
new: true
upsert: true
)
In our use case, 8 commands are sent at the same time and sometimes we get 1 such error (not always).
Current document matching:
> db.collectionName.find({a:31910, b: "2021-09-02T00:00:00Z"})
{ "_id" : ObjectId("613062a3a00a6ac1f7687e5e"), "b" : "2021-09-02T00:00:00Z", "a" : 31910, "c" : 389723 }
Is this expected? Am I missing something?
We can add some retry mechanism in our code but I'd like to understand why the auto retry does not work.
Any comment will be appreciated.
Top User Comments
JIRAUSER1257066 commented on Wed, 29 Sep 2021 15:09:50 +0000:
Hi gjourdanweil@gmail.com,
Thanks for following up! Given that we've discussed that this a risky backport, I will close this as a duplicate of SERVER-47212 based on the discussion you had with james.wahlin on insert when possible" class="issue-link" data-issue-key="SERVER-14322">SERVER-14322.
Best,
Edwin
JIRAUSER1262197 commented on Tue, 28 Sep 2021 07:28:13 +0000:
From https://jira.mongodb.org/browse/SERVER-14322?focusedCommentId=4087196&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-4087196:
SERVER-47212 tracks this issue for the findAndModify command. The fix is currently available in MongoDB 5.0, but was deemed as risky to backport to 4.4 or earlier.