This is my code:
router.post('/findmanychallengesbyid', auth, function(req, res, next){
if(!req.body.ids){
return res.status(400).json({message: 'Geen ids'});
}
var challengeData = [];
for( var i = 0; i < JSON.parse(req.body.ids).length; i++ ) {
Challenge.findById(JSON.parse(req.body.ids)[i].toString().replace(/\"/g, ""), function (err, doc){
challengeData.push(doc);
});
}
res.json(challengeData);
});
Challenge is a schema from my nodejs app.
When I do res.json(JSON.parse(req.body.ids)) I get:
[
"56313da58c5ba50300f2b4f0",
"564cac9c097c07030038cac0",
"563140668c5ba50300f2b4f3"
]
Challenge.findById requires this as input:
56313da58c5ba50300f2b4f0
Now it gets this as input:
"56313da58c5ba50300f2b4f0"
So how can I accomplish this?