Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56718

findOneAndUpdate sometimes failing to update a document

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • ALL

      We have a PSA setup running Mongo 4.0.7.

      We are using the node.js driver: "mongodb": "3.1.1"

      In one process we create an object in the db via a call to one of our REST services. The call to insert the object is as follows:

      const result = await client.db(dbname)
      .collection(COLLECTION_NAME)
      .insertOne(clone(alert), { writeConcern: { j: true } });

       
      Once our rest service returns to the calling operation it calls another operation on the rest service passing in the id of the newly created object.
      The first thing the service does is perform a read in mongo by id. This returns the object.
      The service then starts a transaction, inserts into some other collections and finally performs a findOneAndUpdate (in the transaction):

      findOneAndUpdate(query, update, options);

       
      The query is just {id: value}, the same object that was used to retrieve the object earlier.
      The update contains the following operations:

      {"$inc":{"a":40,"b":1},"$set":{"c.d":1620309757604},"$addToSet":{"e":["f","g"]}}
      

      For some reason, on some occasions the update fails to update anything and we see a response like:

      {"lastErrorObject":{"n":0,"updatedExisting":false},"value":null,"ok":1,"operationTime":"6959177415704707439","$clusterTime":{"clusterTime":"6959177415704707439","signature":{"hash":"AAAAAAAAAAAAAAAAAAAAAAAAAAA=","keyId":0}}}
      

      When this happens there are a lot of actions happening in Mongo although there is no  contention on this item.

      The transaction is then committed successfully (all be it with this missing write).

      Do you know my the item can be read but then in a transaction it cant be found to be updated?

      Thanks in advance.

            Assignee:
            edwin.zhou@mongodb.com Edwin Zhou
            Reporter:
            leigh.jones@ripjar.com Leigh Jones
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: