【发布时间】:2021-01-13 17:53:18
【问题描述】:
我有一个看起来像这样的文档
{
_id:1,
list_id:23,
name:'list01'
cards:[
{
id:3,
name:'card01'
categories:[{
id:10,
category:'section01',
tags:[{id:11,name:'tag01',is_selected: true}]
}]
}
]
}
对于给定的 list_id,我需要将一些数据插入/推送到选定 category 中的 tags 数组,但出现错误说
MongoError:在路径中找到太多位置(即“$”)元素 'cards.$.categories.$.tags'
这是我尝试过的查询。这个查询有什么问题关于如何实现这一点的任何想法?
db.collection(TABLE)
.updateOne(
{ list_id: 23, 'cards.categories.category': 'section01'},
{ $push: { 'cards.$.categories.$.tags': { name: 'tag02', id: uuidv4(), is_selected: true } } }
);
【问题讨论】:
-
不能使用多个$位置,使用arrayFilters,
标签: mongodb mongodb-query