如何修改mongodb文档中的数据里的值
{"_id":ObjectId("53ba69dc6b6c3622c8a16653"),"name":"array1","books":[{"id":1.0,"sale"...
{
"_id" : ObjectId("53ba69dc6b6c3622c8a16653"),
"name" : "array1",
"books" : [{
"id" : 1.0,
"sale" : 10.56,
"title" : "MongoDB实战"
}, {
"id" : 2.0,
"sale" : 50.98,
"title" : "Apache集群"
}, {
"id" : 2.0,
"sale" : 99.99,
"title" : "LoadRunner实战"
}],
"phone" : ["Lenovo", "Samsung"]
}
我有一个文档,想把books数组中的sale为99.99的id改为3,该如何写
db.arrays.update({name:"array1"},{$set:{"books.1.id":4}})
这种定位的写法我知道,只是想看看能不能根据数组内容定位到某个对象上 展开
"_id" : ObjectId("53ba69dc6b6c3622c8a16653"),
"name" : "array1",
"books" : [{
"id" : 1.0,
"sale" : 10.56,
"title" : "MongoDB实战"
}, {
"id" : 2.0,
"sale" : 50.98,
"title" : "Apache集群"
}, {
"id" : 2.0,
"sale" : 99.99,
"title" : "LoadRunner实战"
}],
"phone" : ["Lenovo", "Samsung"]
}
我有一个文档,想把books数组中的sale为99.99的id改为3,该如何写
db.arrays.update({name:"array1"},{$set:{"books.1.id":4}})
这种定位的写法我知道,只是想看看能不能根据数组内容定位到某个对象上 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询