Mongoose FindOneandUpdate - Only update Specific fields leave others alone

Solution 1:

Use $set to update only certain fields.

PlayerInfo.findOneAndUpdate({steamID: req.body.steamID },{ $set: {'yourcoll.$.someField': 'Value'} }, { upsert: true, new: true }).then(playerinfo =>{
     res.json(playerinfo)
});

Documentation:

https://docs.mongodb.com/manual/reference/operator/update/set/

Solution 2:

Fixed. created a object inside $set then to update old values without replacing you need to wrap them in quotes. 'main_server.game_stats.kills' : req.body.....kills etc.

I also did a for loop in the object and assigned props to handle multiple values or single if passed through from json.