mongodb备份之导出和导入某个表

mongoexport is a utility that produces a JSON or CSV export of data stored in a MongoDB instance

WARNING:

Avoid using mongoimport and mongoexport for full instance production backups. They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.

所以全量备份数据使用mongodump和mongorestore
1、导出

--host :要导出数据库 ip
--port :要导出的实例节点端口号
--username :数据库用户名
--password :数据库用户密码
--collection :要导出的表名
--db :要导出的表所在数据库名
--out :要导出的文件路径(默认为当前文件夹)

mongoexport  --collection ai_session_conversa --db ai_xbot --out ai_session_conversa.json
mongoexport  --collection ai_session_message --db ai_xbot --out ai_session_message.json

2、导入

-- host :要导入的数据库 ip
--port :要导入的实例节点端口号
--username :数据库用户名
--password :数据库用户密码
--collection :要导入的表名
--db :要导入的表所在数据库名
--file :要导入的源文件路径(默认为当前文件夹)

mongoimport  --collection ai_session_conversa --db ai_xbot --file ai_session_conversa.json

猜你喜欢

转载自blog.csdn.net/q936889811/article/details/80733349