I'm on step 3 of trying to enable Mongo DB authentication. When I try to create a user via the Mongo shell exactly as the directions indicate, the shell reports:
TypeError: Property 'createUser' of object admin is not a function
I started mongod with the --auth option and switched to the admin database. as always, help appreciated.
Starting in version 4.2 of the mongo shell, you can use the passwordPrompt() method in conjunction with various user authentication/management methods/commands to prompt for the password instead of specifying the password directly in the method/command call.
If you are using Mongo 2.4 or earlier versions, then use addUser
instead of createUser
.
Mongo 2.4
Use this (as mentioned here) for a read and write user along with dbAdmin role:
db.addUser( { user: "joe",
pwd: "secret",
roles: [ "readWrite", "dbAdmin" ]
} )
For a read-only user:
db.addUser( { user: "joe",
pwd: "secret",
roles: [ "read" ]
} )
(See all possible user roles here.)
Mongo 2.2
For a read/write user as mentioned here:
use mydb;
db.addUser("joe", "secret");
For a read-only user as mentioned here:
use mydb;
db.addUser("joe", "secret", true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With