Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError occurs when trying to enable Mongo DB authentication

Tags:

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.

like image 885
dingalla Avatar asked Apr 12 '14 19:04

dingalla


People also ask

How do I authenticate a user in mongo shell?

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.


1 Answers

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);
like image 200
arun Avatar answered Sep 19 '22 13:09

arun