mongoose query: find an object by id in an array

后端 未结 2 587
粉色の甜心
粉色の甜心 2021-02-10 13:18

How could I find an image by id in this Schema. I have the id of the User and the id of the image I am looking for. What would be the best way to do this and do all images in th

2条回答
  •  终归单人心
    2021-02-10 13:29

    When you are interested in the full object it is a simple find:

    .find({"facebook.id":"", "images.id":})
    

    I don't think that there is a way to reduce the image array in the result.

    To update a single element in the image array you can use this:

    .update({"facebook.id":"", "images.id":}, {$set : {"images.$.main" :false} } );
    

提交回复
热议问题