Update Elements in Array

后端 未结 1 1877
春和景丽
春和景丽 2021-01-16 09:28

Lets say I have this Object:

{town_id: 13, houses_data: [
    {house_id: 5, price: 32, description: \"thats a house\"},
    {house_id: 2, price: 12, descript         


        
相关标签:
1条回答
  • 2021-01-16 09:36

    You might use $ to update the first embedded document matching the given query:

    db.test.town.update({town_id: 13, "houses_data.house_id":5},
                        {$set: { "houses_data.$.description": "sold"}})
    
    0 讨论(0)
提交回复
热议问题