【发布时间】:2016-08-18 22:09:14
【问题描述】:
我搜索了一些类似的例子,但没有找到好东西。
{
"_id" : ObjectId("571dea148234534308a290e"),
"user" : "myusername",
"duration" : "",
"test_details" : [
{
"test" : "New",
"test_id" : "0",
"comments" : "will be some text",
"text" : ""
},
{
"test" : "**to change value here**",
"test_id" : "1",
"comments" : "will be some text",
"text" : "**to change value here**"
},
{
"test" : "New",
"test_id" : "2",
"comments" : "will be some text",
"text" : ""
},
{
"test" : "New",
"test_id" : "3",
"comments" : "will be some text",
"text" : ""
"sub_test_details" : [
{
"56eed334534566ac5668ca18" : [
{
"sub_test" : "New",
"sub_test_id" : "0",
"sub_comments" : "will be some text",
"sub_text" : ""
},
{
"sub_test" : "New",
"sub_test_id" : "1",
"sub_comments" : "will be some text",
"sub_text" : ""
},
{
"sub_test" : "New",
"sub_test_id" : "2",
"sub_comments" : "will be some text",
"sub_text" : ""
}
]
},
{
"56eed3b1f37d66ac5668ca19" : [
{
"sub_test" : "New",
"sub_test_id" : "0",
"sub_comments" : "will be some text",
"sub_text" : ""
},
{
"sub_test" : "New",
"sub_test_id" : "1",
"sub_comments" : "will be some text",
"sub_text" : ""
},
{
"sub_test" : "**to change value here**",
"sub_test_id" : "2",
"sub_comments" : "will be some text",
"sub_text" : "**to change value here**"
}
]
}
]
},
{
"test" : "New",
"test_id" : "4",
"comments" : "will be some text",
"text" : ""
}
],
}
问题是:
什么是更新 text="Completed Successfully" 和 test="Done" where _id" 的查询:ObjectId("571dea148234534308a290e").test_id=1。
什么是更新 sub_text="Sub Completed Successfully" 和 sub_test="Sub Done" where _id" 的查询:ObjectId("571dea148234534308a290e").test_details.test_id=3.sub_test_details.56eed3b1f37d66ac5668ca19.sub_step_id=2
在我的情况下,我将获得 id、test_id、exam_num(56eed3b1f37d66ac5668ca19)、sub_test_id 将是参数找到相关的地方进行更新。 数组元素的大小并不总是恒定的。因此,我使用 id 来准确指定我要查找的元素。
谢谢
【问题讨论】:
标签: mongodb