MongoDB数据导入导出指令

windows环境下 , 利用mongoexport 与 mongoimport指令, 将数据从远程数据库使用JSON文件形式导出, 以及将本地数据使用JSON文件形式导入远程数据库.

1.进入mongoDB安装bin目录, cmd打开命令窗口,输入指令

2.导出数据

mongoexport -h 需要导出数据的远程数据库的IP与端口 -u 远程数据库用户名 -p 远程数据库密码 -d 指定数据库名 -c 指定需要导入数据的集合 -o C:\xxx\xxx.json --type json

3.导入数据

mongoimport -h 需要导入数据的远程数据库的IP与端口 -u 远程数据库用户名 -p 远程数据库密码 -d 指定数据库名 -c 指定需要导入数据的集合 --file C:\xxx\xxx.json --type json 

options:
  --help                  produce help message
  -v [ --verbose ]        be more verbose (include multiple times for more verbosity e.g. -vvvvv)
  --version               print the program's version and exit
  -h [ --host ] arg       mongo host to connect to
  --port arg               port. Can also use --host hostname:port
  --ipv6                  enable IPv6 support (disabled by default)
  -u [ --username ] arg   username
  -p [ --password ] arg   password
  --dbpath arg         directly access mongod database files in the given path, instead of connecting to a mongod  server - needs to lock the data directory, so cannot be used if a mongod is currently accessing the same path
  --directoryperdb        if dbpath specified, each db is in a separate directory
  -d [ --db ] arg         database to use
  -c [ --collection ] arg collection to use (some commands)
  -f [ --fields ] arg     comma separated list of field names e.g. -f name,age
  --fieldFile arg         file with fields names - 1 per line
  -q [ --query ] arg      query filter, as a JSON string
  --csv                  export to csv instead of json
  -o [ --out ] arg        output file; if not specified, stdout is used
  --jsonArray             output to a json array rather than one object per

mongoexport -h xxx -u xxx -p xxx -d xxx -c xxx -o C:\xxx.csv --type csv -f "machineCode,sleepStage,template,attrs" -q "{\"template\":\"T10\",\"status\":true}"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容