【发布时间】:2020-01-06 02:08:59
【问题描述】:
我有这个聚合命令,需要覆盖当前文档;
db.collection.aggregate([
{
$project: {
class: "Apples",
imageUrl: { $substr: [ "$imageUrl", 0, { $indexOfBytes: [ "$imageUrl", "\n" ] } ] }
}
}
])
Collection:
{
id:...
class:"Apples"
imageUrl:"..."
}
有多个文档需要更新。这是我目前附加到上述命令但它不起作用的内容。
.forEach( doc => db.product.updateOne( { _id: doc._id }, { $set: { imageUrl: doc.imageUrl } } ) )
提前致谢!
【问题讨论】:
标签: arrays mongodb mongodb-query aggregation-framework