Details
-
Bug
-
Status: Closed
-
Major - P3
-
Resolution: Duplicate
-
2.6.5, 2.7.7
-
None
-
None
-
ALL
Description
If one tries to $setOnInsert an array or increment a positional (or several) elements of that array if that document already exists, the instruction fails. Depending on the order by which they are placed on the update statement it resolves 2 different error messages:
- $setOnInsert before $inc
db.t.update({_id:'12345',hour:12345},{ $setOnInsert: { rpm: [10, 15] }, $inc: { count: 1, 'rpm.$0': 10, 'rpm.$1': 15 }}, { upsert:true })
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 16836,
"errmsg" : "cannot use the part (rpm of rpm.$0) to traverse the element ({rpm: [ 10.0, 15.0 ]})"
}
})
- $seOnInsert after $inc
db.t.update({_id:'12345',hour:12345},{ $inc: { count: 1, 'rpm.$0': 10, 'rpm.$1': 15 }, $setOnInsert: { rpm: [10, 15] }}, { upsert:true })
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 16836,
"errmsg" : "Cannot update 'rpm.$0' and 'rpm' at the same time"
}
})
In either situation this operation should be valid since it's very common, specially for time series operations/use cases, where we need to preallocate arrays and increment counters if those already exist.
The code reveals that we do not treat this valid situation:
https://github.com/mongodb/mongo/blob/master/src/mongo/db/ops/path_support.cpp#L110
https://github.com/mongodb/mongo/blob/master/src/mongo/db/ops/update_driver.cpp#L270-L278
Attachments
Issue Links
- duplicates
-
SERVER-10711 $setOnInsert mods should not conflict with non-insert modifiers
-
- Closed
-