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

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

我正在执行以下脚本以在 mongo 数据库中创建自定义角色。我的数据库名称是 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

问题是 db.createRole 不是命令。

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

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

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