aheckmann / gridfs-stream

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

how to remove all files? #107

Open heinhoang opened 7 years ago

heinhoang commented 7 years ago

I tried this but not works:

gfs.remove({}, function(err) {
        if(err) {
            res.send('We meeting error: ' + err);
            return;
        }
        res.send('All image are deleted succesfully!');
    });
ghasemikasra39 commented 7 years ago

me too. I'm trying to find a way to delete all files in one shot.

healiha commented 7 years ago

This is due to the fact that the .remove() function must take at least _id or filename as parameter as per the documentation. https://github.com/aheckmann/gridfs-stream/blob/8fe8c845a194dc0caeb75db598fad63f998d1e8f/lib/index.js#L81

You could make a pull request with a new Grid function to clear either the current or a specific collection.

If you want to do it without adding a new function, you can also do Grid.files.remove({}). Be aware that it will remove all documents from the current collection. In case you want to do it on a specific collection, you should use Grid.collection('name').remove({}).

Chukstart commented 5 years ago

How can one

This is due to the fact that the .remove() function must take at least _id or filename as parameter as per the documentation. https://github.com/aheckmann/gridfs-stream/blob/8fe8c845a194dc0caeb75db598fad63f998d1e8f/lib/index.js#L81

You could make a pull request with a new Grid function to clear either the current or a specific collection.

If you want to do it without adding a new function, you can also do Grid.files.remove({}). Be aware that it will remove all documents from the current collection. In case you want to do it on a specific collection, you should use Grid.collection('name').remove({}).

Can you delete multiple files at once

rathipradha commented 4 years ago

Hi I need to delete many files in single request gfs.files.deleteMany({_id: { $in: req.params.ID }}, (err, result) => {......})

Whether deletemany is possible...please show me the correct format