removing a row in mongodb isn't seem to be that easy as in SQL lol, well, my issue is that I cant remove a row by the _id because the _id contains an obj ObjectId, that's the row in the db,
{
"_id" : ObjectId("541ec60e41b46b841adde31e"),
"name" : "TT"
}
and this is how I'm trying to remove it,
db.books.remove({ _id: book_id}, function(err, delete) {
if(err)
console.log("ERROR!", err);
console.log("deleted ", delete);
});
I've no idea how to pass the book_id so the query will run as expected,
hope you guys will be able to help me find a solution for this one.
thanks!
Convert book_id to an ObjectId first:
var ObjectId = require('mongodb').ObjectID;
...
db.books.remove({ _id: ObjectId(book_id) }, ...);