我一直在寻找关于此的解释(我明显做错了)到目前为止没有运气,我在我的数据库上有这个集合:
db.activeCustomers.find().pretty();
{
"_id" : ObjectId("58ade8f280648c78cee70b5a"),
"name" : "Gustavo",
"lastName" : "Lara",
"age" : 25,
"hobbies" : [
"rubik",
"guitar",
"games"
],
"sex" : "male"
}
{
"_id" : ObjectId("58ade8f280648c78cee70b5b"),
"name" : "Diana",
"lastName" : "Lara",
"age" : 23,
"sex" : "female"
}
{ "_id" : ObjectId("58ade8f280648c78cee70b5c"), "sex" : "female" }
{
"_id" : ObjectId("58adf5a65da705df647fcbe0"),
"name" : "Juan",
"lastName" : "Pérez",
"age" : 34,
"sex" : "male"
}
我想用这个来更新第三个对象(只有_id和性别的对象):
db.activeCustomer.update({_id: ObjectId("58ade8f280648c78cee70b5c")}, {$set: {name: "Myrna", lastName: "Guerrero", age: 26}});
但没有数据更新,我明白了:
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
根据this,我做得对,也许我做了错误的API功能组合,或者它是一个版本的东西?提前谢谢。
P.S。我使用mongo v3.4.1
答案 0 :(得分:0)
好吧,这只是一个错字:
db.activeCustomer.update({...
它应该是activeCustomer s