-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 5.0.14
-
Component/s: None
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Hello,
I have a spring boot application (`2.7.3`), which is using the reactive mongodb driver. The database is `5.0.11-focal` (docker image).
The problem is that when I execute a query created like below (kotlin)
fun addRequests(requests: List<RequestCountReport>) =
template.getCollection(REQUEST_COUNT_COLLECTION)
.flatMapMany { c ->
val updates = requests.map { r ->
val time = r.time.date()
UpdateOneModel<Document>(
BasicDBObject(
mapOf(
"_id" to r.scope + " " + time,
"scope" to r.scope,
"time" to time,
)
),
BasicDBObject(
mapOf(
"\$inc" to BasicBSONObject(
r.requests.mapKeys { "requests.${it.key}" }
)
)
),
UpdateOptions().upsert(true)
)
}
c.bulkWrite(updates).toFlux()
}
.then()
(`RequestCountReport` has the following structure)
data class RequestCountReport( val scope: String, val time: Temporal, val requests: Map<String, Int>, )
...which is translated to the following query to mongo
{
"update": "requestCount",
"ordered": true,
"txnNumber": 3,
"$db": "route",
"$clusterTime": {
"clusterTime": {
"$timestamp": {
"t": 1670768591,
"i": 1
}
},
"signature": {
"hash": {
"$binary": {
"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"subType": "00"
}
},
"keyId": 0
}
},
"lsid": {
"id": {
"$binary": {
"base64": "OdYdXMkcQ+CxD2BbLWRsog==",
"subType": "04"
}
}
},
"updates": [
{
"q": {
"_id": "admin 2022-12-11",
"scope": "admin",
"time": {
"$date": "2022-12-11T00:00:00Z"
}
},
"u": {
"$inc": {
"requests.here,maptile,road,truck,fleet": 187
}
},
"upsert": true
}
]
}
it sometimes gives an error like this
Write errors: [BulkWriteError{index=0, code=11000, message='E11000 duplicate key error collection: route.requestCount index: _id_ dup key: { _id: "xxxxxx 2022-12-10" }', details={}}].
at com.mongodb.internal.connection.BulkWriteBatchCombiner.getError(BulkWriteBatchCombiner.java:167) ~[mongodb-driver-core-4.6.1.jar:na]
I initially had a single op write (one for each entry) and it also occurred, but then I could at least retry the given entry write. Now, when it is a bulk, I am not sure even how to do it (something may be saved, it is not in the transaction I assume). Nevertheless, it is a bug IMO
- related to
-
SERVER-14322 Retry on predicate unique index violations of update + upsert -> insert when possible
-
- Closed
-