MongoDB NodeJS > db.createRole is not a function

20 views
Skip to first unread message

Nicholas Grealy

unread,
Oct 14, 2018, 6:36:25 PM10/14/18
to node-mongodb-native

Hi all,


(Disclaimer: I've also asked this question on stackoverflow)


I'm using the "Node.js MongoDB Driver API", and I was hoping to convert my database initialisation scripts to NodeJS.


I can't find any admin commands (e.g. db.createRole()db.grantPrivilegesToRole()). Do these functions exist somewhere else? OR is there some alternative workaround I can use? (e.g. runCommand)


Here is the full code snippet.


db_test.js


const MongoClient = require('mongodb').MongoClient

MongoClient.connect('mongodb://admin:password@localhost:27017/admin')
  .then(client => client.db('admin').admin())
  .then(db => {
    return db.createRole({
      role: 'SOME_ROLE',
      privileges: [],
      roles: []
    })
  })
  .then(() => {
    console.log('Success!')
    process.exit(0)
  })
  .catch(err => {
    console.log('Error! - ' + err.message)
    process.exit(99)
  })


Output:

Error! - db.createRole is not a function

Library: "mongodb": "3.1.4"

Reply all
Reply to author
Forward
0 new messages