Db. copyDatabase ("from", "to", "127.0.0.1: 16161 ");
Replace the from library on 127.0.0.1. Copy to the to library.
This has an additional benefit. That is, the from database may have deleted the data. We know that the disk space will not be released when data is deleted. Refer to another article in the blog: the disk space is not released after mongodb deletes the set.
It can occupy a lot of disk space. Although you can use db. repairDatabase () to repair data. But this method has two bad points. 1. Accidental stopping of operations in production may cause the risk that data cannot be restored. 2. If the disk space is insufficient, it is smaller than the current space occupied by the db time. In this case, db. repairDatabase () cannot be used.
This section describes how to use db. copyDatabase to back up and copy data.
1. db. copyDatabase ("from", "to", "127.0.0.1: 16161"); copy a new to database. This is the minimum data used. Related data files to will be generated in the data directory.
2. Change the configuration of all programs from the from library to the to library. The test is correct.
3. You can delete the from database. Method. Use from and then db. dropDatabase (). The advantage of this method is that the data on the disk can be deleted in time. Save a lot of space.
If the disk is insufficient, refer to the above method.