Assuming you are using gridfs-stream module, then when you call gfs.remove
with an object, it will expect that the object will contain an _id
.
You need to first get the id, using MongoDb driver.
// This should be your files metadata collection, fs.files is the default collection for it.
var collection = db.collection('fs.files');
collection.findOne({'metadata.relation': req.body._id }, { _id : 1 }, function (err, obj) {
if (err) return cb(err); // don't forget to handle error/
gfs.remove(obj, function(err){
if (err) return false;
return true;
})
});