且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MongoDB db.copyDatabase在未经授权时失败

更新时间:2023-12-01 15:39:22

我遇到相同的错误,但是在尝试复制集合时:

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); });