How to update array of object data using object index number in node js?

I need to update object 1 status: “pending” to status: “completed”. How to do this…?

Hi JOSIEY_Vengappallil,

I am new to this community. I am not sure how to update the object in array through index.

Please check the below approach, it might help.

db.getCollection(collectionName).update({"username" : "JAMES BOND", "taskList.title" :"meeting"},
{$set : {"taskList.$.status" : "completed"}})

This will update only matched document in an array.

1 Like