I'm trying to create an api where I receive 2 parameters, the id of the session and the seat that needs to be reserved
[
{
"id":1,
"tanda" : "7:30am"
, "asientos" : [
0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0 ,0, 0
]
},
{
"id":2,
"tanda" : "9:00am",
"asientos" : [
0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0, 0 ,
0, 0, 0 ,0, 0
]
}
the query to mongo is this
db.horarios.update({"id":2}, {"$set" : {"asientos.8" : "1"}});
but wanting to do it in nodejs
router.put('/reservar/:id/:asiento', function(req, res, next) {
horarios.update({"id": req.params.id}, { "$set":{ "asientos." + req.params.asiento +: "1"}}, function(err, doc) {
if (err) {
console.log(err);
return res.status(400).json({"error"});
}
if (doc.result.nModified) {
res.status(200).json({"status": "ok"});
} else {
res.status(400).json({"error": "No se pudo reservar el asiento"});
}
});
I get SyntaxError error: Unexpected token +