MongoDB Bulk Delete gridfs file instance _mongodb

Source: Internet
Author: User
Tags mongodb

The platform has a large number of pictures have been used, the order of magnitude of millions, almost 100G of space, whether it is too wasteful?

Copy Code code as follows:

Db.fs.files.find ({filename:/xxx/}). ForEach (function (n) {db.fs.files.update {filename:u.filename},{$set: { filename:newname}},false,true)}//Regular batch is changed to a fixed name for easy deletion.
Mongofiles-port 12345-d xxx Delete newname//mongofies to kill these files according to the filename in batches.

Db.repairdatabase ()///special Note that the above deletion is not a physical deletion, chunks file is actually still in, show DBS or db.stats () found that the size of DB has not changed, to perform db.repairdatabase () Note that this action is a global write lock, memory and CPU consumption, and processing time is related to the size of the file, be sure to do during off-peak hours.


Almost 1 hours later over, comfortable, 100G space Ah!!!

The

is aware the This command can take a long time to run if your the database is large. In addition, it requires a quantity of free disk spaces equal to the size of your database. If you are lack sufficient free spaces on the same volume, your can mount a separate volume and use this for the repair. In this case, you must run the command line and use The–repairpath switch to specify the folder in which to store the TEM Porary repair files.
Warning:this Command obtains a global write lock and would block other operations until it has completed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.