Muhammad Danyal
Muhammad Danyal

Reputation: 61

Update query in mongodb

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?

Upvotes: 1

Views: 120

Answers (1)

Joe
Joe

Reputation: 28336

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.

Upvotes: 1

Related Questions