-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Unknown
-
None
-
Affects Version/s: 2.1.0
-
Component/s: None
Per the documentation, I was expecting to be able to simply provide a replacement document when performing an upsert, but the rust driver does not allow that.
Example that works fine from mongodb CLI:
rs0:PRIMARY> db.things.insert({"thing_id": "thing101", "destination": "place1", "version": "1.0.0"}) WriteResult({ "nInserted" : 1 }) rs0:PRIMARY> db.things.update({"thing_id": "thing101"}, {"bot_id": "thing101", "destination": "place2", "version": "1.0.0"}, {upsert: true}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) rs0:PRIMARY> db.things.update({"thing_id": "thing102"}, {"bot_id": "thing102", "destination": "place2", "version": "1.0.0"}, {upsert: true}) WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : ObjectId("62264fc80b57d4095f779d06")}) rs0:PRIMARY>
However, since update_one() calls update_one_common(), which immediately calls bson_util::update_document_check(), which demands an update operator, this method of specifying a replacement document is not supported by the mongodb rust driver.
I will workaround using on the $set update operator, of course, but this is a gap I didn't see noted anywhere.