Home > System Tutorial > LINUX > body text

How to import, export, backup and restore mongodb

WBOY
Release: 2024-06-02 09:02:36
Original
834 people have browsed it

mongodb 如何导入导出备份恢复

1. Back up Mongodb
mongodump -h RuiyIp -d dataname -o /home/aa/dev/mongodb/data
Copy after login

mongodump mongo Export database command mongodump --help You can view all the help under this command

    -h export source
    -d Database name to be exported
    -o The location where the database is to be exported

After the terminal scrolls through N lines, the database export is completed. You can go to the /home/aa/dev/mongodb/data directory to view the exported file, which is in bson format (I did not export it immediately after exporting. I saw the file, but it took a while for it to appear, for unknown reasons).

2. Restore using: mongorestore command
mongorestore -d cmsdev  /home/xx/dev/mongodb/data/cmsdev
Copy after login
    -d Database name used

Add the directory you just exported directly after it, so that all tables can be restored directly. If -c is to restore one table

3. Import
mongoimport -d my_mongodb -c user user.dat
Copy after login

Parameter Description:

    -d specifies the library to use, in this case "my_mongodb"
    -c specifies the table to be exported, in this case "user"

You can see that the table structure will be created implicitly when importing data

4. Export
mongoexport -d my_mongodb -c user -o user.dat
Copy after login

Parameter Description:

    -d specifies the library to use, in this case "my_mongodb"
    -c specifies the table to be exported, in this case "user"
    -o specifies the file name to be exported, in this case "user.dat"
    As you can see from the above, the export method uses the JSON style

The above is the detailed content of How to import, export, backup and restore mongodb. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template