Show dbs not returning anything

image

It is a new mongo db installed on windows server 2012 R2, I have not enabled any authentication myself.
mongo db shell version 4.2.22
mongo db server version 4.2.16

“errmsg”:“command insert requires authentication”
“codeName”:“Unauthorized”

this is a clear indication that your server has authentication enabled. check your command or config file for the auth parts

and since you haven’t logged in with a password, you cannot see any databases, nor do other operations. you either need to login with a password or you can give db.auth(username).

3 Likes

Which config file should I check for auth?
When you say login with a password, I have not even set any authentication to my mongo Db.
Can you please elaborate on the steps?

Hello :wave: @Shubhi_Jain

You can find the MongoDB config file at a certain location for the given OS:

Platform Method Configuration File
Linux apt , yum , or zypper Package Manager /etc/mongod.conf
macOS brew Package Manager /usr/local/etc/mongod.conf (on Intel processors), or/opt/homebrew/etc/mongod.conf (on Apple M1 processors)
Windows MSI Installer <install directory>\bin\mongod.cfg

For more info, refer here: https://www.mongodb.com/docs/manual/reference/configuration-options

@Yilmaz_Durmaz means you have started the mongod with the

security:
   authorization: "enabled"

So, now you have to authenticate using db.auth() with the username and password.

I hope it helps!

Thanks,
Kushagra

3 Likes

it is easy for us to miss small but important keywords, which in this case “a new mongo db installed”.

And by “installed” I am guessing you have used an “exe/msi” pack to install. To be honest, I haven’t used that method before, but it seems the default config comes with auth enabled.

Is it the Enterprise version? That might also affect your auth depending on your selected settings during installation, especially login mechanisms.

Another important thing is that if you start a new server on a new data folder for the first time with auth enabled, the first thing you should do is to add an admin user, and a database user if needed. I have checked “msi” installation pages (community/enterprise) and there was no mention of this important detail. So I will give that to you for the confusion.

Anyways, if you are the only one to use this server for now, then find the default config file at places @Kushagra_Kesav detailed above. then disable auth and restart the server (the file is indentation-sensitive, so keep an eye on it)

security:
    authorization: "disabled"

for more auth options and how to set it up, please check this manual/tutorial:

1 Like

My mongod config file has nothing mentioned under security
image


This is the error when I try creating an admin user as mentioned in the doc

use admin
db.createUser(
{
user: “Admin”,
pwd: “myNewPassword”,
roles: [ { role: “userAdminAnyDatabase”, db: “admin” } ]
}
)

it is impossible to do anything else without disabling auth. you need to find the location of the config file the server uses.

I don’t have a windows server, nor had installed mongodb with an msi/exe, so I can only speculate on possible solutions.

  • try to check service settings; run mmc and check what options/flags mongod service uses.
  • if it is not in services, check start up programs for a sign of mongodb server start.

PS: th service might be set to use other auth modes other than username/password like using system admin account. check for this possibility too.

By default authentication is not enabled on Windows as per my experience
Check few llines from mongod.log when your mongod started
It will clearly say with a warning message that access control is disabled if Authorization is not enabled in your config file

1 Like

I have tried installing community/enterprise version on windows 10 pro machine. I had no luck to replicate enabling auth during installation. I still wonder how you get yours with auth enabled.

anyways, I have found this command to try.

  • open cmd console. or open powershell and then start cmd in it. it has to be cmd console because next command is confused by one of PS commands.
  • use sc qc mongodb to see the details of the service.

You should have an output similar to the following, showing the location of the config file in the BINARY_PATH_NAME the service uses.

C:\Windows\system32>sc qc mongodb
[SC] QueryServiceConfig SUCCESS

SERVICE_NAME: mongodb
        TYPE               : 10  WIN32_OWN_PROCESS
        START_TYPE         : 2   AUTO_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : "C:\Program Files\MongoDB\Server\6.0\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\6.0\bin\mongod.cfg" --service
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : MongoDB Server (MongoDB)
        DEPENDENCIES       :
        SERVICE_START_NAME : LocalSystem

check the config file in this path and report back what you find.

2 Likes