它可能是一些很小的东西,但是对于我的生活,我无法弄清楚如何在我的mongodb中更新嵌入式文档。以下是我试图更新的文件:
db.customers.insert({
_id: 'custId2',
Fname:"john" ,
Lname:"Mandel" ,
Pnum:"051-895421" ,
Mnum:"087-478512" ,
orders: {
Orddate:"25-10-2015" ,
Ordtime:"15.50" ,
ProdType: "accessory",
Product: "USB Drive",
Netcost:40 ,
},
address: {
Billingaddress:"21 Culrua, Brown Street, Portlaw, Co.Wexford" ,
Deliveryaddress:"21 Culrua, Brown Street, Portlaw, Co.Waterford"
}
});
这是我试图做的更新查询
db.customers.update(
{Fname: "john" },
{
$set{
"address.Billingaddress":"34 Vegas Street",
"address.Deliveryaddress":"34 Vegas Street"
}
}
);
但是,当我运行它时,我得到了这个错误,但我看不出我错过了什么
Syntax error: Unexpected Token {
答案 0 :(得分:0)
实际上您的查询是正确的,但在:
之后您遗漏了$set
个小问题,因此查询如下:
db.customers.update({
"Fname": "john"
}, {
"$set": {
"address.Billingaddress": "34 Vegas Street",
"address.Deliveryaddress": "34 Vegas Street"
}
})
检查mongo update 。