TypeError:对象admin的属性“createRole”不是函数

时间:2015-01-02 19:14:46

标签: mongodb

我正在执行以下脚本以在mongo db中创建自定义角色。我的数据库名称是admin

db.createRole(
   {
     role: "updaterRole",
     privileges: [
       { resource: { cluster: true }, actions: [ "killop", "inprog" ] },
       { resource: { db: "", collection: "" }, actions: [ "createCollection" ] },
       { resource: { db: "", collection: "" }, actions: [ "createIndex" ] },
       { resource: { db: "", collection: "" }, actions: [ "insert" ] },
       { resource: { db: "", collection: "" }, actions: [ "find" ] },
       { resource: { db: "", collection: "" }, actions: [ "update" ] }
     ],
     roles: []
   }
)

但我得到了以下错误。

TypeError: Property 'createRole' of object admin is not a function

1 个答案:

答案 0 :(得分:0)

问题是db.createRole不是命令。

要创建角色,请使用以下命令:

db.runCommand( { createRole: ... } )

来源:http://docs.mongodb.org/manual/reference/command/createRole/