mongoDB通过mongoexport
程序将mongodb
实例中的数据存储在json
或csv
文件中导出。例如:
mongoexport --host mongodb1.example.net --port 37017 --username user --password "pass" --collection contacts --db marketing --out mdb-example.json
为了确保
mongoexport
正常连接,你至少需要目标数据库的读取权限。
注意事项
当你在本地测试数据导出时,应该在mongo.exe
之外,新启用一个cmd
窗口来执行mongoexport
命令。否则会出现MongoDB SyntaxError: missing ; before statement @(shell)
的错误。
为了演示方便,先向test
数据库的users
集合中插入下面数据:
{ "_id" : ObjectId("5c21fae76818ba7cb05df771"), "username" : "benben_2015", "country" : "China", "age" : 20 }
{ "_id" : ObjectId("5c21fb136818ba7cb05df772"), "username" : "Tylar Swift", "country" : "American", "age" : 21 }
命令参数详解
连接参数
在3.4.6版本中,使用一个新的参数--uri &l