samedi 28 février 2015

Mongoose+Node API delays db query

GET works great, DEL works great too. but POST... : What happens is that string goes in db. It does not show up(on my webapp). When I add a second string, it finally shows up. As if there is a delay?



app.post('/api/todos', function(req, res) {
todo.create({
text : req.body.text,
done : true
}, function(err, todo) {
if (err)
res.send(err);
});
todo.find(function(err, todos){
if(err)
res.send(err)
res.json(todos);
});


But if I do it with delete, it works like normal. deleted the id and show the rest of the id's.



app.delete('/api/todos/:todo_id', function(req, res){
todo.remove({
_id : req.params.todo_id,
}, function(err, todo){
if(err)
res.send(err);
});
todo.find(function(err, todos){
if(err)
res.send(err)
res.json(todos);
});
});


I hope my question makes sense, I'm not so good at english


Aucun commentaire:

Enregistrer un commentaire