I want to update any index of FirstCol array dynamically in Nodejs. How do I go about doing that in this collection.
{
"TableId": "0",
"FirstCol": [
"Have high energy ",
"Talk more than listen "
]
}
I know I can update a specific array index using the dot operator. For eg:
db.testcol.update(
{ "TableId": "0" },
{ $set:
{
"FirstCol.1": "rain gear"
}
}
)
But what if I did not know that I have to edit index 1 of array FirstCol. How to frame the update query in order to update the index of the array which is suppose in variable 'editIndex'. Can I do something like:
db.testcol.update(
{ "TableId": "0" },
{ $set:
{
"FirstCol.editIndex": "rain gear"
}
}
)
Need your help. Thanks :)
db.arr.update({},{ $set: { "arr.0" : 'Your updated text' } }, {many:false})