Update query in mongodb

Viewed 46

Suppose I have this document in mongodb collection:

{
  "_id": {
    "playerId": "113069",
    "tournamentId": "197831"
  },
  "__v": 0,
  "playerName": "David WArner",
  "pointsTotal": 426
}

I update it using this update query(using mongoose):

await PointsTotal.findOneAndUpdate(
      {
        _id: {
          playerId: player._id,
          tournamentId: tournamentId,
        }
      },
      {
        $set: {
          playerName: playerName,
          pointsTotal: totalPoints
        },
      },
      {
        upsert: true,
      }
    );
  }

But, if the playerName and totalPoints is same as before updating, will it perform update operation to overwrite these fields and I am able to listen this update in change stream or not?

1 Answers

No, if there is no change to the document MongoDB will not perform a write, there will be no operation in the oplog, and nothing will appear in the change stream.

Related