0

yes I just started to understand MongoDB. Therefore I have installed MongoDB in the folder "Program files" yesterday and tryed to figure out, how to work with it.

Today I simply tryed to start it again. But something went wrong. To understand the beginning better I deinstalled MongoDB, deleted the MongoDB, data, log folders and have installed MongoDB again direct on c:/.

Started the server:

mongod --directoryperdb --dbpath c:\mongodb\data\db --logpath c:\mongodb\log\mongo.log --logappend --auth --rest --install

Started the service:

net start MongoDB

And the Mongo shell:

mongo

Now I try "show dbs" with the following result:

>show dbs
2017-09-14T10:41:49.541+0200 E QUERY    [thread1] Error: listDatabases failed:{
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
    "code" : 13,
    "codeName" : "Unauthorized"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
shellHelper.show@src/mongo/shell/utils.js:769:19
shellHelper@src/mongo/shell/utils.js:659:15
@(shellhelp2):1:1

More I haven't done already. What can I do to show the dbs?

Of cource, I have tryed the learnings of the following post to, without success: show dbs gives "Not Authorized to execute command" error

NewbieXXL
  • 155
  • 1
  • 1
  • 11
  • Please refer following answer https://stackoverflow.com/a/29472184/5089586 – Rahul Nikam Sep 14 '17 at 09:56
  • Rather than getting frustrated and saying things like "of course I tried", actually "show us what you tried" instead. The error says your user is not authorized. So show how you set up the user you are trying to work with. Also simply typing `mongo` does not "authenticate a user". Type in `mongo --help` and actually read the usage as to how to suppy the username and password. – Neil Lunn Sep 14 '17 at 10:00
  • For the new installation I did't create a user. Unfortunately I'm not able to figure out if users have alived the deinstallation. – NewbieXXL Sep 14 '17 at 10:42

1 Answers1

0

Looks like you are starting the db with --auth but not connecting with username/password. If you have not created any user then remove --auth and restart db. Then you will be able to connect.

  • Because monogdb is allready running I deactivated the service in the msconfig. Now I started it again with: mongod --directoryperdb --dbpath c:\mongodb\data\db --logpath c:\mongodb\log\mongo.log --logappend --rest --install If if try to connect with "mongo" the connect failed – NewbieXXL Sep 15 '17 at 07:36
  • ok, I forgott to start the Service again. Now the connection works and I will try to handle the admin – NewbieXXL Sep 15 '17 at 07:39
  • it seems, I needed to add an administrative user role at first. now I can list the databases with show dbs. fi you dont't think so, give me please a sign. I really would like to understand mongodb. – NewbieXXL Sep 15 '17 at 08:20
  • When you first time start mongo, do not enable auth. Then you will be able to connect without any problem. Once started you can connect and create admin user. Then you can restart mongo with auth. Now connect using the previously created admin user then you will not have any problem. This is just one way there may be other. – JavaProgrammer12 Sep 15 '17 at 18:47