MongoDB数据操作

MongoDB数据集合常见操作

导出数据

  • 导出整个数据库所有集合,即数据备份

    mongodump -h dbhost -d dbname -o dbdirectory

MongoDB数据备份工具

  • 导出单个集合

    $ mongoexport -d test -c students -o students.json

reference 传送门

导入数据

  • 导入整个数据库(备份文件)
    mongorestore --host 127.0.0.1:MOGODBPORT -d testFile testFilePATH/
  • 倒入单个集合
mongoimport --host 127.0.0.1:PORT -d test -c users ./user.json

数据上传与下载

  • 打包
    tar zcvf testFile.tar.gz testFile

  • 解压缩
    tar xvf testFile

  • 上传包到服务器
    scp -P SEVERPORT ./testFile USER@<ip>:/PATH

  • 从服务器下载到本地
    scp -P SEVERPORT USER@<ip>:/PATH ./testFile

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容