[英]How to copy database from one server to another in mongodb
I am trying to copy a database [mongodb] in production server hosted in nginx to my local dev environment setup [linux machine]. 我正在尝试将Nginx托管的生产服务器中的数据库[mongodb]复制到本地开发环境设置[linux计算机]。
I tried the solution given in following url How do I copy a database from one MongoDB server to another? 我尝试了以下url中给出的解决方案如何将数据库从一台MongoDB服务器复制到另一台服务器?
But when I establish a ssh tunnel and try to copy, I am getting following error 但是,当我建立ssh隧道并尝试复制时,出现以下错误
db.copyDatabase("admin","testadmin","localhost:27018")
{
"ok" : 0,
"errmsg" : "couldn't connect to server localhost:27018, connection attempt failed"
}
if I try to copy the database directly in my destination server. 如果我尝试直接在目标服务器中复制数据库。 I am getting the following error
我收到以下错误
db.copyDatabase("admin","testadmin","mongodb://<remotehostname>:27017")
{
"operationTime" : Timestamp(1545126863, 1),
"ok" : 0,
"errmsg" : "Must specify set name for replica set ConnectionStrings",
"code" : 9,
"codeName" : "FailedToParse",
"$clusterTime" : {
"clusterTime" : Timestamp(1545126863, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
Please help. 请帮忙。 I am stuck with issue for two days.
我被问题困扰了两天。 I am not sure whether I can use mongodump and restore.
我不确定是否可以使用mongodump和还原。 I am using mongo version 3.4 in my remote server and mongo version 3.6 in my local.
我在远程服务器上使用mongo 3.4版,在本地服务器上使用mongo 3.6版。 Could this be a problem?
这可能是个问题吗?
I also tried adding replica set, but got below error. 我也尝试添加副本集,但出现以下错误。 How to find the replica set name?
如何找到副本集名称?
db.copyDatabase("admin","testadmin","mongodb://<remotehostname>:27017/?replicaSet=test")
{
"operationTime" : Timestamp(1545117923, 135),
"ok" : 0,
"errmsg" : "Bad digit \"/\" while parsing 27017/?replicaSet=test",
"code" : 9,
"codeName" : "FailedToParse",
"$clusterTime" : {
"clusterTime" : Timestamp(1545117923, 135),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
An alternative would probably be to use mongoDump/mongorestore. 一种替代方法可能是使用mongoDump / mongorestore。
https://stackoverflow.com/a/22201759/5107937 https://stackoverflow.com/a/22201759/5107937
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.