i have a document which consists on nested array. i need to update nested array object value whose position is dynamic. i need to update locators:id value :'obj1' to value :'obj2'. But the problem is these locators position are not static they will be always dynamic
{
"_id" : ObjectId("5cf8fcac9f938484cb872ed2"),
"projectId" : "pID92",
"pageName" : "trail",
"image" : "2e",
"pageId" : "1",
"objectName" : [
{
"objectName" : "demoPage",
"attributes" : [
{
"locators" : "tagName",
"value" : "p"
},
{
"locators" : "className",
"value" : "btnKeyEvent"
},
{
"locators" : "id",
"value" : "obj1"
},
{
"locators" : "text",
"value" : "Login"
}
]
"pomObject" : "newtrial1(driver).demo_1vij"
}
]
}
i tried by hard coding the object position like this
db.objectRepository.update({
$and:[
{pageName:'trail'},
{'objectName.objectName':'demoPage'},
{'objectName.attributes':{$elemMatch: {"locators": 'id',
"value": 'obj1'}}}
]},
{"$set": { "objectName.0.attributes.2.value" : 'obj2'}})
please tell me how to solve this. Thank You
Expected out put
{
"_id" : ObjectId("5cf8fcac9f938484cb872ed2"),
"projectId" : "pID92",
"pageName" : "trail",
"image" : "2e",
"pageId" : "1",
"objectName" : [
{
"objectName" : "demoPage",
"attributes" : [
{
"locators" : "tagName",
"value" : "p"
},
{
"locators" : "className",
"value" : "btnKeyEvent"
},
{
"locators" : "id",
"value" : "obj2"
},
{
"locators" : "text",
"value" : "Login"
}
]
"pomObject" : "newtrial1(driver).demo_1vij"
}
]
}

