I search for some similar example, but didn't find something good.
{
"_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" : ""
}
],
}
And the questions are:
What is query to update text="Completed Successfully" and test="Done" where _id" : ObjectId("571dea148234534308a290e").test_id=1.
What is query to update sub_text="Sub Completed Successfully" and sub_test="Sub Done" where _id" : ObjectId("571dea148234534308a290e").test_details.test_id=3.sub_test_details.56eed3b1f37d66ac5668ca19.sub_step_id=2
In my case i will get id, test_id, exam_num(56eed3b1f37d66ac5668ca19), sub_test_id will be parameters to find relevant place for updating. An array elements size not always constant. Therefore I use id to specify exactly which element I am looking for.
Thanks