1.db.media.copyTo('test1')报错
解决办法:
在官网 http://docs.mongodb.org/manual/reference/command/eval/#dbcmd.eval 有一段描述:
If authorization is enabled, you must have access to all actions on all resources in order to run eval.
Providing such access is not recommended, but if your organization requires a user to run eval,
create a role that grants anyAction on anyResource. Do not assign this role to any other user.
2.解决步骤
新建一个角色
use admin
db.createRole({role:'sysadmin',roles:[],privileges:[{resource:{anyResource:true},actions:['anyAction']}]})
在现有的用admin上增加 sysadmin 角色
use admin
db.grantRolesToUser( "admin", [ { role: "sysadmin",db:"admin"} ] )
3.切换到目标数据库执行db.media.copyTo('test1')