findOneAndUpdate return interface and not the document

Hi,

I’m in front of the following issue.
When I use findOneAndUpdate() the result is an interface

{
  acknowledged: true,
  modifiedCount: 1,
  upsertedId: null,
  upsertedCount: 0,
  matchedCount: 1
}

Below the code and the package.json:

return client.db(infos.db).collection(infos.collection).updateOne(
        {machine_number: 192512},
  
        {
          $set: {comments : "comm1", designation : "designation1", "new field" : "field"},
        },
        { upsert: false, returnDocument: 'after' },
       
      )
"dependencies": {
    "express": "^4.18.2",
    "mongodb": "^4.13.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.20"
  }

Is it the expected result? On the documentation, I thought I heard the result should be the updated document.

Thanks

@zak_aria the query you are running uses updateOne, afaik this doesnt return the new doc. However, findOneAndUpdate does: FindOneAndUpdateOptions | mongodb

3 Likes

@santimir thanks. It’s bad copy/paste :roll_eyes:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.