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"