美文网首页
MongoDB数据操作

MongoDB数据操作

作者: HiFi不二 | 来源:发表于2017-09-11 09:53 被阅读28次

    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

    相关文章

      网友评论

          本文标题:MongoDB数据操作

          本文链接:https://www.haomeiwen.com/subject/geyxsxtx.html