MongoDB update nested array

后端 未结 1 365
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 07:25

I have a simple structure in mongodb, with nested array. How can I update searched value? I\'ve seen examples using numbers something like this:

invited.0.us         


        
1条回答
  •  伪装坚强ぢ
    2021-01-07 08:16

    update({ invited.key : 84026702 }, { invited.$.used : true });
    

    This basically does what you wanna and should work nicely. Look into positional operators in mongodb: http://www.mongodb.org/display/DOCS/Updating#Updating-The%24positionaloperator

    Or in PHP (as your question is tagged) you can do:

    $mongo->collection->update(array('invited.key' => 84026702), array('invited.$.used' => true));
    

    0 讨论(0)
提交回复
热议问题