20

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.

dingalla
  • 1,219
  • 3
  • 12
  • 19

2 Answers2

26

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);
arun
  • 10,685
  • 6
  • 59
  • 81
17

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.

dingalla
  • 1,219
  • 3
  • 12
  • 19
  • 2
    This error actually appears to be caused by the version of `mongo`, i.e. the CLI, used too. A version 2.4 client on a version 2.6 `mongod` also results in this error. – zelanix Oct 24 '14 at 14:11