findOneAndUpdate - Update the first object in array that has specific attribute

后端 未结 1 1221
孤城傲影
孤城傲影 2021-01-07 03:06

I have an object that has attributes. This includes an array of other Objects that have their own attributes.

Lobby:
  --> \"a\": \"b\"
  --> \"c\": \"         


        
相关标签:
1条回答
  • 2021-01-07 03:53

    I managed to find a working solution!

    Game.findOneAndUpdate({'a': 'b', 'Players.status': 'open'}, { $set : { 'Players.$': player} },
    function (err, doc) {
        if (err) {
            console.log(err);
        } else {
            // Do stuff
        }
    });
    
    0 讨论(0)
提交回复
热议问题