我在MongoDb中有一个复杂的文档,如下所示
{ title: "Star Wars", episodes: { 0: { episode: 1, title: "The Phantom Menace" }, 1: { episode: 2, title: "Attack of the Clones" } } }
如何根据标题删除第1集?就像我想删除《幽灵的威胁》
vc9ivgsu1#
试试这个:
db.collection.aggregate([ { $set: { episodes: { $filter: { input: "$episodes", cond: { $ne: ["$$this.title", "The Phantom Menace"] } } } } } ])
Mongo Playground
1条答案
按热度按时间vc9ivgsu1#
试试这个:
Mongo Playground