MongoDB pull element from array two levels deep

后端 未结 1 683
Happy的楠姐
Happy的楠姐 2020-12-22 06:16

I have a collection with the following items :

{ \"Queries\" : [  {  \"Results\" : [  {  \"id\" : 1 },  {  \"id\" : 2 } ] } ], \"_id\" : ObjectId(\"51ddb6f9b         


        
1条回答
  •  旧时难觅i
    2020-12-22 06:52

    This is the query you have to use:

    db.collection.update( { "Queries.Results.id":1 }, { $pull: { "Queries.$.Results": {"id":1} } } )
    

    You need to specify the "where" clause in order to find the document to update. You are also missing the positional operator $, you have to use it because Queries can have multiple Results.

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