20
votes

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.

2

2 Answers

26
votes

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);
17
votes

The issue was I was trying to execute this function against mongod 2.4.9 which apparently isn't supported. This error message does not occur in the 2.6.0 release.