以下のようにMongoDBにドキュメントがあります。
{
"CorePrice" : 1,
"_id" : 166,
"partno" : 76,
"parttype" : "qpnm",
"shipping" :
[
{
"shippingMethod1" : "ground",
"cost1" : "10"
},
{
"shippingMethod2" : "air",
"cost2" : "11"
},
{
"shippingMethod3" : "USPS",
"cost3" : "3"
},
{
"shippingMethod4" : "USPS",
"cost4" : 45
}
]
}
私の目標は、CorePrice (1) を cost4 (45) に追加し、計算された値を新しい列「dpv」として取得することです。以下のクエリを使用してみました。ただし、エラーが表示されますexception: $add only supports numeric or date types, not Array
。理由はわかりません。どんな種類の助けも大歓迎です。
db.Parts.aggregate([
{
$project: {
partno: 1,
parttype: 1,
dpv: {$add: ["$CorePrice","$shipping.cost1"]}
}
},
{
$match: {"_id":{$lt:5}}
}
]);