I have a MongoDB database that resides on a remote server machine whose IP address is 192.168.1.20 on a local network. For development and testing purposes, and since I am not allowed to modify or delete the database on the server for security purposes, I want to copy the database on my local machine for my personal use.
我有一个MongoDB数据库驻留在本地网络上IP地址为192.168.1.20的远程服务器上。出于开发和测试的目的,由于出于安全考虑,我不允许在服务器上修改或删除数据库,因此我想在本地计算机上复制数据库以供个人使用。
Can anyone please tell me, how do I achieve this?
任何人都可以告诉我,我怎么做到这一点?
5 个解决方案
#1
5
There is copy database command which I guess should be good fit for your need.
有复制数据库命令,我认为应该适合您的需要。
db.copyDatabase("DATABASENAME", "DATABASENAME", "localhost:27018");
Alternatively, you can just stop MongoDb, copy the database files to another server and run an instance of MongoDb there.
或者,您可以停止MongoDb,将数据库文件复制到另一台服务器并在那里运行MongoDb实例。
#2
15
I do this by creating a dump of the remote db to my local machine, which I then restore:
我通过创建远程数据库转储到我的本地计算机来执行此操作,然后我将其还原:
-
Make sure you have a mongo instance up and running (eg. run
mongod.exe
from your bin folder in a terminal window. On my windows computer that's C:\mongodb\bin)确保你有一个mongo实例启动并运行(例如,从终端窗口中的bin文件夹运行mongod.exe。在我的Windows计算机上是C:\ mongodb \ bin)
-
Make a dump from remote db: Open a new terminal window, move to the bin folder again, run:
从远程数据库进行转储:打开一个新的终端窗口,再次移动到bin文件夹,运行:
mongodump -h example.host.com --port 21018 -d dbname --username username --password yourpass
mongodump -h example.host.com --port 21018 -d dbname --username username --password yourpass
(Change the parameters to suit your own situation.)
(更改参数以适合您自己的情况。)
-
Restore the dumped database: Once the dump has been made, run the following command so that you have a local db:
还原转储的数据库:转储完成后,运行以下命令以便拥有本地数据库:
mongorestore -d theNameYouWantForYourLocalDB dump\nameOfRemoteDB
mongorestore -d theNameYouWantForYourLocalDB dump \ nameOfRemoteDB
(replace nameOfRemoteDB with the name of the remote db, the same as in previous command, and replace theNameYouWantForYourLocalDB with the name that you want your new local db to have)
(将nameOfRemoteDB替换为远程数据库的名称,与上一个命令相同,并将NameYouWantForYourLocalDB替换为您希望新的本地数据库具有的名称)
#3
1
The mongoexport command: http://docs.mongodb.org/manual/core/import-export/
mongoexport命令:http://docs.mongodb.org/manual/core/import-export/
Or, mongodump command: http://docs.mongodb.org/manual/reference/program/mongodump/
或者,mongodump命令:http://docs.mongodb.org/manual/reference/program/mongodump/
#4
1
mongodb has commandline tools for importing and exporting. Take a look at mongodump --collection collection --db test
and mongorestore --collection people --db accounts dump/accounts/
mongodb具有用于导入和导出的命令行工具。看看mongodump --collection collection --db test和mongorestore --collection people --db accounts dump / accounts /
http://docs.mongodb.org/v2.2/reference/mongodump/ http://docs.mongodb.org/v2.2/reference/mongorestore/
http://docs.mongodb.org/v2.2/reference/mongodump/ http://docs.mongodb.org/v2.2/reference/mongorestore/
this even works over the network
这甚至适用于网络
#5
0
You can use the mongoexport command to copy the database to your local machine.
您可以使用mongoexport命令将数据库复制到本地计算机。
#1
5
There is copy database command which I guess should be good fit for your need.
有复制数据库命令,我认为应该适合您的需要。
db.copyDatabase("DATABASENAME", "DATABASENAME", "localhost:27018");
Alternatively, you can just stop MongoDb, copy the database files to another server and run an instance of MongoDb there.
或者,您可以停止MongoDb,将数据库文件复制到另一台服务器并在那里运行MongoDb实例。
#2
15
I do this by creating a dump of the remote db to my local machine, which I then restore:
我通过创建远程数据库转储到我的本地计算机来执行此操作,然后我将其还原:
-
Make sure you have a mongo instance up and running (eg. run
mongod.exe
from your bin folder in a terminal window. On my windows computer that's C:\mongodb\bin)确保你有一个mongo实例启动并运行(例如,从终端窗口中的bin文件夹运行mongod.exe。在我的Windows计算机上是C:\ mongodb \ bin)
-
Make a dump from remote db: Open a new terminal window, move to the bin folder again, run:
从远程数据库进行转储:打开一个新的终端窗口,再次移动到bin文件夹,运行:
mongodump -h example.host.com --port 21018 -d dbname --username username --password yourpass
mongodump -h example.host.com --port 21018 -d dbname --username username --password yourpass
(Change the parameters to suit your own situation.)
(更改参数以适合您自己的情况。)
-
Restore the dumped database: Once the dump has been made, run the following command so that you have a local db:
还原转储的数据库:转储完成后,运行以下命令以便拥有本地数据库:
mongorestore -d theNameYouWantForYourLocalDB dump\nameOfRemoteDB
mongorestore -d theNameYouWantForYourLocalDB dump \ nameOfRemoteDB
(replace nameOfRemoteDB with the name of the remote db, the same as in previous command, and replace theNameYouWantForYourLocalDB with the name that you want your new local db to have)
(将nameOfRemoteDB替换为远程数据库的名称,与上一个命令相同,并将NameYouWantForYourLocalDB替换为您希望新的本地数据库具有的名称)
#3
1
The mongoexport command: http://docs.mongodb.org/manual/core/import-export/
mongoexport命令:http://docs.mongodb.org/manual/core/import-export/
Or, mongodump command: http://docs.mongodb.org/manual/reference/program/mongodump/
或者,mongodump命令:http://docs.mongodb.org/manual/reference/program/mongodump/
#4
1
mongodb has commandline tools for importing and exporting. Take a look at mongodump --collection collection --db test
and mongorestore --collection people --db accounts dump/accounts/
mongodb具有用于导入和导出的命令行工具。看看mongodump --collection collection --db test和mongorestore --collection people --db accounts dump / accounts /
http://docs.mongodb.org/v2.2/reference/mongodump/ http://docs.mongodb.org/v2.2/reference/mongorestore/
http://docs.mongodb.org/v2.2/reference/mongodump/ http://docs.mongodb.org/v2.2/reference/mongorestore/
this even works over the network
这甚至适用于网络
#5
0
You can use the mongoexport command to copy the database to your local machine.
您可以使用mongoexport命令将数据库复制到本地计算机。