aheckmann / gridfs-stream

Easily stream files to and from MongoDB
MIT License
615 stars 120 forks source link

Remove file does not delete chunks #82

Open slasktrat opened 9 years ago

slasktrat commented 9 years ago

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;
            });
slasktrat commented 9 years ago

I've managed to temporarily work around it by calling:

gfs.db.collection(req.params.bucket + '.chunks').remove({files_id:file._id}, function(err) { ...
mh4ck commented 8 years ago

Same here! How to remove it if i only got gfs as object? What is in req.params.bucket?

slasktrat commented 8 years ago

Name of the file bucket where you stored the file. If no name specified, it defaults to 'fs'

mh4ck commented 8 years ago

Thank you! :+1

zevero commented 7 years ago

Still not removing chunks... workaround works, but this is not pretty!

stefano-lupo commented 6 years ago

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!

pzemljic-git commented 6 years ago

adding the root option worked for me gfs.remove({_id: req.params.id, root: 'myFiles'}, function (err) {

rathipradha commented 4 years ago

TypeError: gfs.deleteMany is not a function There is possible to use deleteMany concept in 'gridfs-stream'