MongoDB db.copyDatabase在未经授权时失败 [英] MongoDB db.copyDatabase fail on unauthorized
问题描述
我正在尝试使用mongo CLI在MongoLab上的两个不同的DB之间复制. 我遵循了文档- http://docs.mongodb.org/manual/reference /method/db.copyDatabase/
I'm trying to copy between two different DBs on MongoLab using the mongo CLI. I followed the docs - http://docs.mongodb.org/manual/reference/method/db.copyDatabase/
- 已连接到目标数据库.
-
运行以下内容:
- Connected to the target DB.
Ran the following:
db.copyDatabase('source-db','target-db','source-host','source-user','source-pwd')
db.copyDatabase('source-db', 'target-db', 'source-host', 'source-user', 'source-pwd')
但是我总是得到:
{ "ok" : 0, "errmsg" : "unauthorized" }
推荐答案
我遇到相同的错误,但是在尝试复制集合时:
I am getting the same error, but when trying to copy a collection:
> db.coll1.copyTo("coll2");
Wed Jul 24 13:32:05 uncaught exception: { "ok" : 0, "errmsg" : "unauthorized" }
我的数据库位于MongoHQ管理的共享服务器上,因此肯定存在一些权限问题,该服务不允许copyTo
或其他命令运行.
My database is on a shared server managed by MongoHQ, so there definitely might be some permission problem there that the service does not allow copyTo
or other commands to run.
一个简单的解决方法是手动获取集合中的所有对象,然后将它们插入第二个集合.这是在实施copyTo
之前完成的工作:
A simple workaround is to manually fetch all the objects in the collection and insert them to the second collection. This is how things were done prior to copyTo
being implemented:
db.coll1.find().forEach(function(o) { db.coll2.insert(o); });
这篇关于MongoDB db.copyDatabase在未经授权时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!