Reputation: 961
I am trying to update a profile picture, but i read GridFS has no update method so i am trying to first delete the record then insert the new one later, but when i try to delete the record, it says "success" but doesn't delete it at all from DB( record still visible), when i added gfs.exist just as a check before deletion, i get the following log, i don't understand why its returning false, when the record does exist and i did try passing the filename too( same error).
console.log("current pid:",req.body.current_pid);
gfs.exist({_id:req.body.current_pid}, function (err, found) {
console.log("found: ", found);
if(found){
gfs.remove({_id:req.body.current_pid}, function (err) {
if (err) return handleError(err);
console.log('success in deletion',err);
});
}
else{
console.log('does not exist',err);
}
});
}
Logs:
current pid: 55b877629f6f5af41c0e25ed
found: false
does not exist null
Upvotes: 1
Views: 1595
Reputation: 961
You need to change it. GridFS expects the default collection "root" to be "fs", so do the methods in gridfs-stream. That's your problem. Just set that method from the "gfs" object gfs.collection("photos")
in your code and it will be find. Otherwise the extra arg to the individual methods take a config object, so:
{ "root": "photos" }
there.
credits - @blake seven
Upvotes: 1