I am using node-orm2 with express. I am trying to delete multiple lines in a database using remove. After all is deleted, i'd like to call a callback when i'm sure everything is done.
var idArray = [{id: 2}, {id: 5}];
I tried :
Person.find({or:idArray}).each().remove().save(function(){
res.writeHead(301, {Location: '/home'});
res.end();
});
but i'm told : cannot used remove on undefined.
So I have to do my method remove inside each
Person.find({or:idArray}).each(function(element){
element.remove();
})
.save(function(){
setTimeout(function(){
res.writeHead(301, {Location: '/home'});
res.end();
},2000);
});
But the callback save is called before each remove is done.
So for the moment i'm using a timeout but I hope there is a better method.
I am using node-orm2 with express. I am trying to delete multiple lines in a database using remove. After all is deleted, i'd like to call a callback when i'm sure everything is done.
var idArray = [{id: 2}, {id: 5}]; I tried :
Person.find({or:idArray}).each().remove().save(function(){ res.writeHead(301, {Location: '/home'}); res.end(); }); but i'm told : cannot used remove on undefined.
So I have to do my method remove inside each
Person.find({or:idArray}).each(function(element){ element.remove(); }) .save(function(){ setTimeout(function(){ res.writeHead(301, {Location: '/home'}); res.end(); },2000); }); But the callback save is called before each remove is done.
So for the moment i'm using a timeout but I hope there is a better method.
Thank you for your answers.