I have a collection of documents similar to the following:
{
_id: ObjectId("..."),
title: "...",
body: "...",
comments: [
{
name: "...",
email: "...",
comment: "..."
},
{
name: "...",
email: "...",
comment: "..."
},
{
name: "...",
email: "...",
comment: "..."
}
]
}
Let's say that I want to update the name field for the second comment. So, I would have a query as follows:
db.posts.update({_id: ""}, {$set: {"comments.2.name": "new name"}});
Now, I'm wondering how could I pass the index of array element (2) as a parameter/variable in node.js?