次のようにデータベースにドキュメントがあります。
{
"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
}]
}
次のコードを使用して繰り返し、 ShippingMethod4 の名前を shippingMethod に変更しようとしています。
remap = function (x)
{
if (x.shipping) {
db.foo.update ({ _id:x._id},
{ $set: {
"shipping.shippingMethod","x.shipping.shippingMethod4" },
$unset:{ "shipping.shippingMethod4":1
}}); } }
ただし、次のエラーがスローされます。
"Sun Oct 06 02:09:44.764 JavaScript execution failed: SyntaxError: Unexpected token ,
理由がわからない。誰か助けてくれませんか?