MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

aggiorna l'array profondamente nidificato mongodb

Puoi provare con mongodb 3.6 arrayFilters

db.collection.update(
  { "_id": ObjectId(5b56bd2f3e18580edc85af73) },
  { "$push": { "Cards.$[card].comments.$[comment].attachments": "2" } },
  { "arrayFilters": { "card.cardID": ObjectId("5b56c895d0a04836f71aa776"), "comment.commentId": 2 } }
)

Assicurati di trasmettere i tuoi ID a ObjectId

Modifica:

db.collection.update(
  { "_id": ObjectId(5b56bd2f3e18580edc85af73) },
  { "$push": { "Cards.$[card].comments.$[comment].attachments": "2" } },
  { "arrayFilters": [
    { "card.cardID": ObjectId("5b56c895d0a04836f71aa776")},
    {"comment.commentId": 2 }
    ]
  }
)