MongoDB(3)- 数据的导入导出
2023-02-18 15:49:49 时间
1.集合数据导入导出
1.1.导出集合数据
- mongoexport:导出数据
- --host:mongodb服务器地址
- --port:mongodb端口
- -u:用户
- -p:密码
- --authenticationDatabase=逻辑库:登录的用户隶属于哪个逻辑库
- -d:要导出哪个逻辑库
- -c:要导出哪个集合
- -f:要导出集合中哪些属性,不加-f默认导所有
- -o:导出的文件输出路径
mongoexport --host=localhost --port=27017 -u admin -p 123456 --authenticationDatabase=admin -d school -c student -o D:/MongoDB/data/student.json
1.2.导入集合的数据
- mongoimport:导入数据
- --host:mongodb服务器地址
- --port:mongodb端口
- -u:用户
- -p:密码
- --authenticationDatabase=逻辑库:登录的用户隶属于哪个逻辑库
- -d:要导入到哪个逻辑库
- -c:要导入到哪个集合
- --file:导入的文件路径
mongoimport --host=localhost --port=27017 -u admin -p 123456 --authenticationDatabase=admin -d test -c test_student --file D:/MongoDB/data/student.json
2.逻辑库数据导入导出
2.1.导出逻辑库的数据
逻辑库导出不仅能导出逻辑库的数据记录,逻辑库的用户等数据均能导出
- mongodump:导出逻辑库
- --host:mongodb服务器地址
- --port:mongodb端口
- -u:用户
- -p:密码
- --authenticationDatabase=逻辑库:登录的用户隶属于哪个逻辑库
- -d:要导出哪个逻辑库;不加-d选项,导出所有逻辑库,一个逻辑库一个文件夹
- -o:导出的路径,不需要加导出的文件名,给出路径即可,会默认生成逻辑库命名的文件夹
- --dumpDbUsersAndRoles:这个选项不用加值,这个只能指定逻辑库,相当于这个选项存在的前提就是:-d必须得有,不然报错
实例:导出指定逻辑库不导出用户
mongodump --host=localhost --port=27017 -u admin -p 123456 --authenticationDatabase=admin -d school -o D:/MongoDB/
2.2.导入逻辑库的数据
- mongorestore:导入逻辑库
- --host:mongodb服务器地址
- --port:mongodb端口
- -u:用户
- -p:密码
- --authenticationDatabase=逻辑库:登录的用户隶属于哪个逻辑库
- -d:要导入到逻辑库;不加-d选项,导出所有逻辑库,一个逻辑库一个文件夹
- --drop:导入前删除逻辑库记录,不加这个选项,直接导入
mongorestore --host=localhost --port=27017 -u admin -p 123456 --authenticationDatabase=admin --drop -d school D:/MongoDB/school
相关文章
- [Linux] 编写Dockerfile文件自动构建镜像
- [Linux] nginx的try_files指令实现隐藏index.php的重写
- [linux] shell脚本编程-统计日志文件中的设备号发通知邮件
- [Linux]F5负载均衡器
- [Go] golang设置运行的cpu数
- [Go] golang的MPG调度模型
- [Linux] 进程间通信
- [linux] 多进程和多线程
- [linux] 进程五状态模型
- Linux系统日志介绍
- Linux系统账户后门及排查
- [Go] golang的用途和windows搭建环境
- Linux操作系统root账号密码获取防范技术研究
- [Linux] Linux系统(进程管理)
- [Linux] ssh秘钥对免密码登陆
- [Linux] Linux系统(用户管理)
- [Linux] Linux系统(文件操作)
- [Linux] Linux系统(登陆、退出、修密码)
- [Linux] host dig nslookup查询域名的DNS解析
- [javaSE] 看博客学习多线程的创建方式和优劣比较和PHP多线程