Inserting data to nested array in mongodb

后端 未结 3 615
青春惊慌失措
青春惊慌失措 2020-12-07 00:24

I have a document which looks like this

{
 _id:1,
 list_id:23,
 name:\'list01\'
 cards:[
  {
   id:3,
   name:\'card01\'
   categories:[{
    id:10,
    categ         


        
3条回答
  •  情歌与酒
    2020-12-07 00:33

    In short, it is not possible.

    Nested Arrays

    The positional $ operator cannot be used for queries which traverse more than one array, such as queries that traverse arrays nested within other arrays, because the replacement for the $ placeholder is a single value

    https://docs.mongodb.com/manual/reference/operator/update/positional/

    However, you may want to try $[]

    Nested Arrays The filtered positional operator $[] can be used for queries which traverse more than one array and nested arrays.

    For an example, see Update Nested Arrays in Conjunction with $[].

    https://docs.mongodb.com/manual/reference/operator/update/positional-filtered/#position-nested-arrays-filtered

提交回复
热议问题