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
I figured it out. I accidentally put the data and logs in same directory as the
\mongodb\bin
. The solution is to put themongodb\data
andmongodb\logs
in a separate folder or drive -- I differentiated usingC:\~
andD:\~
drives.