存在带有变体作为数组的产品模型。我想将其priceInternational字段更新为(priceIndia * conversionRate + priceIndia * marginFactor)的总和。
以下是查询-
Product.update({
and : [{
variants : { neq : [] }
},{
'variants.$[].priceInternational' : { neq : undefined }
}
]
}, {
$set : {
'variants.$[].priceInternational' : {
$sum : [{
$mul : { 'variants.$[].priceIndia' : conversionRate }
}, {
$mul : { 'variants.$[].priceIndia' : marginFactor }
}]
}
}
}, {multi : true}, function(error, response){
console.log(error, JSON.stringify(response))
})
这给出了错误-
{ MongoError: The dollar ($) prefixed field '$sum' in 'variants.0.priceInternational.$sum' is not valid for storage.
at Function.MongoError.create (/Users/ankit/Projects/jaypore-ecommerce/jaypore-server/node_modules/mongodb-core/lib/error.js:45:10)
at toError (/Users/ankit/Projects/jaypore-ecommerce/jaypore-server/node_modules/mongodb/lib/utils.js:149:22)
at /Users/ankit/Projects/jaypore-ecommerce/jaypore-server/node_modules/mongodb/lib/collection.js:1029:39
at /Users/ankit/Projects/jaypore-ecommerce/jaypore-server/node_modules/mongodb-core/lib/connection/pool.js:544:18
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
请帮忙或提出其他可行的查询方法。