【发布时间】:2023-03-27 02:35:01
【问题描述】:
我在 NodeJS 中有以下更新查询,其中包含 mongoose 3.5.5 使用的底层 mongodb 驱动程序,使用最新的 MongoDB 服务器 4.2.5 社区:
await mongoose.connection.db.collection('cluster1kms').updateOne({"location.coordinates": [point.longitude, point.latitude]}, {
$set: {
weight: {
$divide: [
{
$add: [
{
$multiply: ["$weight", "$count"]
},
point.weight
]
},
{
$add: ["$count", 1]
}
]
}
},
$inc: {"count": 1}
}, {upsert: false});
如标题所示,我不断收到$divide 不是有效存储名称的问题。 MongoDB 应该允许在更新中聚合管道,但我似乎没有成功。在网上的MongoDB web shell中也尝试了同样的方法,错误是一样的。
我错过了什么吗?
谢谢
【问题讨论】: