I try to find and remove an item.
Here is my code , its simple:
playlistItem.find( { $and: [ { songId : data.songId }, { userAdded : data.userAdded } , { playlistId : data.playlistId } ] } ).limit(1).lean().exec(function(err, item){
if (!item) {
callback(null,{message:"playlist item not found"})
}else{
// delete playlist item
item.remove(function(err) {
if (err){
callback( new Error('new error') );
}else{
callback(null,{message:"playlist successfully removed"})
}
});
}
})
i want first find my item and then remove it
when i run this code i get this error:
item.remove(function(err) {
^
TypeError: Object [object Object] has no method 'remove'
I want know where i am wrong.
Thanks for your helping.
I assume that you want to delete the object. Obviously, the model does not have such a method to delete it directly.
Since you are using Mongoose, this is the query that deletes an object from the database:
Model.remove({ id: X }, function (err) {
if (err) return handleError(err);
// removed!
});
So, in your case, I would assume that something like this should work:
PlayListItems.remove({ id: item.id }, function (err) {
if (err) return handleError(err);
// removed!
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.