Based on my code below, I am looking to set a variable to the req.body.update. I can't figure out how to accomplish this. When I set it to queryz nothing happens.
I am using mongoose for this.
app.put('/application/todoupdate/:id/:index', function(req, res, next) {
console.log('accessed put route');
let item = 0;
let queryz = "todos." + item + ".todoText";
console.log(queryz);
User.where({_id: req.params.id}).update({
$set: {
"todos.0.todoText": req.body.update
// queryz: req.body.update
}
}).then(
res.send(req.body.update)
)
});
My data base stucture is:
{
"_id": {
"$oid": "77777777777"
},
"todos": [
{
"todoText": "req success",
"timestamp": "7777777777777"
},
{
"todoText": "something",
"timestamp": "7777777777777"
}
]
}
What I came to was which allowed me to access the lower level:
app.put('/application/todoupdate/:id/:timestamp', function(req, res, next) {
console.log('accessed put route');
User.where({_id: req.params.id, "todos.timestamp":
req.params.timestamp}).update({
$set: {
"todos.$.todoText": req.body.update
}
}).then(
res.send(req.body.update)
)
});