MongoDB: Not authorized on Admin

3.2k views Asked by At

I'm beginning to use MongoDB and have spent several hours troubleshooting without resolve. From what I understand, there first needs to be a root user before there can be an authorized/admin user.

I installed in C:\mongodb\, then setup --dbpath in C:\mongodb\data and --logpath in C:\mongodb\logs\log.txt.

I installed then ran the MongoDB service, accessible in the services.msc

My recipe to disaster was:
1. mongo localhost,
2. use admin
3. db.createUser({ user: 'root', pwd: '123456', roles:['root']})

Then get "Error: couldn't add user: not authorized on admin to execute command { createUser ....."

I am running MongoDB shell version: 2.6.5 and greatly appreciate any help that leads to a solution.

Thank you,
Leo

1

There are 1 answers

0
leocreatini On BEST ANSWER

I figured it out. I accidentally put the data and logs in same directory as the \mongodb\bin. The solution is to put the mongodb\data and mongodb\logs in a separate folder or drive -- I differentiated using C:\~ and D:\~ drives.