盒子
盒子

mongo的备份、导入、导出

今天mlab突然抽风,本地的测试项目也没法运行了。没办法,只好用本地的mongo了。mlab上的数据库也可以只有的导入导出,之前导入了项目的数据,现在可以导出,然后导入进本地的数据库中。
(PS:本地的mongorestore、mongoimport等操作直接讲cmd指向在mongo/bin中然后输入命令即可,不需要在mongo命令行下运行。)

1
2
3
4
5
6
7
8
9
10
11
Binary
Import database
mongorestore -h dbhost -d foowala -u <user> -p <password> <input db directory>
Export database
mongodump -h dbhost -d foowala -u <user> -p <password> -o <output directory>
Import collection
mongorestore -h dbhost -d foowala -u <user> -p <password> <input .bson file>
Export collection
mongodump -h dbhost -d foowala -c <collection> -u <user> -p <password> -o <output directory>

mlab上导出数据或者单条collection的命令如上。

得到数据库后我们直接使用mongorestore -h 127.0.0.1 -d test dapath导入即可。

支持一下
扫一扫,支持wind
  • 微信

  • 支付宝