Uploaded image for project: 'Rust Driver'
  1. Rust Driver
  2. RUST-1209

upsert replacement document gets error "update document must have first key starting with '$"

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown 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.

            Assignee:
            kaitlin.mahar@mongodb.com Kaitlin Mahar
            Reporter:
            dwputney@gmail.com David Putney
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: