How do I update multiple fields in a document while using findOneAndUpdate?

Hi, I am wondering how I update multiple fields at the same time when using findOneAndUpdate. Currently I have:

const filter = {_id:};
const update = {player2: req.body.player2};

const updatedGame = await Game.findOneAndUpdate(filter, update);

Where Game is a Mongoose schema. What I want to accomplish is to update more than just the player2 field in the Game model in the same call. How do I do this?

Turns out this is very easy, all you gotta do is make the second argument (update) an object that takes all the changes you are trying to make. Sorry about pulling the trigger too early on this one. It is very easy to do.

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