vsivsi / meteor-file-collection

Extends Meteor Collections to handle file data using MongoDB gridFS.
http://atmospherejs.com/vsivsi/file-collection
Other
159 stars 37 forks source link

How to delete the whole file collection #162

Closed dpatte closed 7 years ago

dpatte commented 7 years ago

I notice that you dont support .remove({})

as per this in your documentation: "For safety, undefined and empty selectors (undefined, null or {}) are all rejected."

So how would I remove everything? By doing a find({}) and deleting each one individually? I believe some of my docs may have lock issues in the collection due to a crash, so I want to rebuild the collection from scratch.

Thx

vsivsi commented 7 years ago

For cases like this you should just manually remove the three underlying collections from MongoDB directly using e.g. the mongo CLI or another admin tool of your choice. gridFS is just two MongoDB collections [name].files and [name].chunks. FC also uses a [name].locks collection. If you blow these three collections away (or remove all documents from them) then you can start fresh.

You can also do this within Meteor code by simply opening each of these collections by name as an ordinary Meteor collection. Then you can do whatever you want to them. Just don't create them the first time this way, because each gridFS collection has special indexes that won't get added properly if you manually create the collections. That's why I recommend just dropping the whole collection if you want to start again.

dpatte commented 7 years ago

Thanks for the advice. I tried removing them individually but it took 5 seconds each in the loop.

vsivsi commented 7 years ago

above comment edited to remove a ton of email header info junk at the bottom of the post

dpatte commented 7 years ago

This worked great for me thank you. Wish there was a way to do this from within Meteor though.