Remove file does not delete chunks
When i delete a file, all related chunks are left behind filling up storage space. Am I supposed to clear the chunks manually?
gfs.collection(req.params.bucket).remove({_id:file._id}, function (err) {
if (err) {
return false;
}
return true;
});
I've managed to temporarily work around it by calling:
gfs.db.collection(req.params.bucket + '.chunks').remove({files_id:file._id}, function(err) { ...
Same here! How to remove it if i only got gfs as object? What is in req.params.bucket?
Name of the file bucket where you stored the file. If no name specified, it defaults to 'fs'
Thank you! :+1
Still not removing chunks... workaround works, but this is not pretty!
I was having the same problems - stemmed from not passing the write db object to the Grid constructor when using mongoose.
I had some boiler plate express code that I had been using that looks like:
mongoose.connect(dbURL);
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
...
const gfs = Grid(db, mongoose.mongo); // BAD!!!
const gfs = Grid(db.db, mongoose.mongo); // Terrible variable names but works
});
However my db variable was actually just a mongoose.connection object and thus I was passing that to the Grid constructor.
Using db.db (or better yet some sensible variable names solves the problem).
Maybe this will help someone else!
adding the root option worked for me gfs.remove({_id: req.params.id, root: 'myFiles'}, function (err) {
TypeError: gfs.deleteMany is not a function There is possible to use deleteMany concept in 'gridfs-stream'