MongoDB 如何将集合从一个本地主机移动到另一个本地主机? [英] MongoDB How to move collection from one localhost to another?
问题描述
我在 Ubuntu 的本地主机上使用 MongoDB(仅用于教育目的),但现在,我有了一台新计算机.所以,我想在我的新电脑上拥有这个收藏.在新机器上安装 MongoDB 后,我需要复制哪些文件才能执行此操作?谢谢.
I was using MongoDB on localhost of my Ubuntu (just for education purpose), but now, I have a new computer. So, I would like to have this collection on my new PC. What files do I need to copy to do this after installing MongoDB on a new machine ? Thank you.
推荐答案
首先你必须阅读 mongo 备份和恢复 这个文档解释了如何备份和恢复你的数据库.
First you must read mongo backup and restore this documentation explain how to backup your data base and restore.
现在您应该按照以下步骤操作:
Now you should follow this steps :
1> 从您的旧 Ubuntu 系统使用以下命令备份您的数据库mongodump --host DB name --port 27017 --out/path 保存文件
此命令以 BSON 格式写入数据,如果您只想从数据库中获取一些集合,请使用 mongodump --collection 您的集合名称 --db 数据库名称
1> From your old Ubuntu systems takes back up of your DB using following command
mongodump --host DB name --port 27017 --out /path to save your files
this command write data in BSON format, if you want to take only some collections from your DB then use mongodump --collection your collection name --db DB name
2> 现在将所有上述 BSON
文件复制到您的新 PC 并使用以下命令恢复旧的 Ubuntu 系统数据库.mongorestore --port <端口号><备份路径>
在运行此命令之前,您必须安装 mongoDB.
2> Now copy all above BSON
files to your new PC and use following command to restore your old Ubuntu systems DB.
mongorestore --port <port number> <path to the backup>
before running this command you must install mongoDB.
这篇关于MongoDB 如何将集合从一个本地主机移动到另一个本地主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!