1、导入初始化脚本数据
首先进入mongodb安装目录,执行以下命令:
格式:mongoimport.exe -d<数据库名称>-c<集合名称> --file <指定导出的目录>
实例:mongoimport.exe -d demo -c user--file e:/user.json
将以下内容存放到user.json格式数据,然后将其导入即可
{"_id":{"$oid":"58f17add8c9da0c870564bb2"},"sex":"女"}
{"_id":{"$oid":"58f17c2c8c9da0c870564bb3"},"name":"张三","sex":"男"}
{"_id":{"$oid":"58f802b8121c1caaa50a014c"},"name":"e生态正在建设中。。","description":"专注于互联网服务","url":"www.eshengtai.net"}
{"_id":{"$oid":"58f803c2121c1caaa50a014d"},"name":"e生态_修身","description":"专注于互联网服务,www.eshengtai.net","url":"www.eshengtai.net"}
{"_id":{"$oid":"58fd65e9dce2ff5e6d5a3b37"},"name":"demo1","description":"测试中。。专注于互联网服务,www.eshengtai.net","url":"www.eshengtai.net"}
{"_id":{"$oid":"58fd65fcdce2ff5e6d5a3b38"},"name":"demo1","description":"测试中。实例1","url":"www.eshengtai.net"}
{"_id":{"$oid":"58fd6a9bdce2ff5e6d5a3b39"},"name":"e生态_修身","age":10.0,"description":"知识分享1"}
{"_id":{"$oid":"58fd6a9bdce2ff5e6d5a3b3a"},"name":"e生态_修心","age":15.0,"description":"知识分享1"}
{"_id":{"$oid":"58fd6a9bdce2ff5e6d5a3b3b"},"name":"e生态_修养","age":20.0,"description":"知识分享1"}
{"_id":{"$oid":"58fd6a9bdce2ff5e6d5a3b3c"},"name":"e生态_分享","age":25.0,"description":"知识分享1"}
{"_id":{"$oid":"58fd6a9bdce2ff5e6d5a3b3d"},"name":"e生态_互联网","age":30.0,"description":"知识分享1"}
{"_id":{"$oid":"58fd6a9ddce2ff5e6d5a3b3e"},"name":"e生态_时代","age":35.0,"description":"知识分享1"}
2、导出指定数据库下指定表数据
格式:mongoexport.exe -d <数据库名称> -c <集合名称> -o <指定导出的目录>
实例:mongoexport.exe -d demo -c user -o e:/user.json
3、查看导入内容