Can't create admin user: ‘createUser’ of object test is not a function

Hi everyone,

I’m a total beginner when it comes to databases and MongoDB in particular.
I installed MongoDB via the current Debian buster package.

I tried to create an admin user as in the MongoDB documentation. I typed:

use admin
db.createUser( {
user: "nombreUsuarioAdmin",
pwd: "contrasenaUsuarioAdmin",
roles: [{role: "root",db: "admin"}]

The response to this command is:

Fri May 1 19:51:45.706 TypeError: Property ‘createUser’ of object test is not a function.

Can you provide a screenshot of what you are doing so that we have some context?

Are you in the shell? Look like it, but I am not sure. It could be the node driver. If in the shell, could you just enter db. It should print admin as you wrote use admin but it thinks it is an object of type test. So may be somewhere you did db = ….

It almost seems like your db shell variable has gotten overwritten. What is returned if you type db in the shell? You should get the name of your current database.

Have you tried closing your mongo shell and restarting it? This will bring everything back to a known good state.

Hi @Stefan_Schmelz,

What is the output of:

version()     // mongo shell version
db.version()  // MongoDB server version 


I am in the shell and running version 3.6.3 [according to version()].
The database is running ao a raspberry pi3 with a 64 bit raspbian buster.
I installed mongodb with sudo apt install -y mongodb and opened the mongo shell after install.

the only commands i entered were:

use admin
db.createUser({user:"admin",pwd: passwordPrompt(),roles:[{role: "userAdminAnyDatabase", db: "admin"}], readWriteAnyDatabase})

and if i test it hosting the database on my computer I get an error like this:
2020-05-01T23:07:40.066+0200 E QUERY [thread1] ReferenceError: passwordPrompt is not defined :

Perhaps it would help if you could point me to a beginner safe explanation of the mongoDB user management and maybe a good book that isnt that expensive?

As for passwordPrompt() according to documentation.

Starting in MongoDB 4.2, you can use passwordPrompt() as the value for the pwd instead of specifying the password.

As for

See, course M001 and M103 to start and then M310.


Hi Stefan,

The documentation is comprehensive (and free!). Just ensure you are referring to the correct version to match your MongoDB deployment: MongoDB 3.6 Manual.

If you are trying to follow tutorials or documentation designed for newer MongoDB versions, these will often rely on newer server and shell features that may not be present in prior releases.

If you want an offline version of the manual, there are also links to HTML and EPUB on the manual home page (link above).


1 Like

I realized that the version I get for the Raspberry PI is 2.4. I managed to create an admin user, but is there a way to build it from source? I would prefer a recent version, but if you can tell me that there is no downside to an older verison i will be happy with the old one.