【发布时间】:2021-12-19 02:40:19
【问题描述】:
是否有机会通过"ID" 和 "lang" 字段触发记录,使用findOneAndUpdate 或findByIdAndUpdate 查询MongoDB 记录?这是数据库对象示例:
{
"id": "61842e6fb19afbc0922f5505",
"locales": [
{
"lang": "ru",
"title": "Тестовый десерт",
"description": "тестовый"
},
{
"lang": "lv",
"title": "Testu deserts",
"description": "Testu descriptions"
},
{
"lang": "en",
"title": "Test dessert",
"description": "Test description"
}
]
}
这就是我尝试触发的方式,但它不起作用:
const filter = {
_id: id,
locales: {
lang: lang
}
}
const product = await Product.findOneAndUpdate(filter, {
lang: {
title,
description,
price
}
}, { new: true });
【问题讨论】:
标签: javascript mongodb mongoose graphql