Maxim Chechenev
Maxim Chechenev

Reputation: 120

MongoDB 2.6.12 - no collections in DB

I have a some problem with MongoDB (2.6.12). I have one database with collections and a lot of data. Then I created user with readWrite role, enabled auth=true in mongod.conf, restarted 'mongod' service.

Looks like auth works fine, but I can't see any data/collections in DB. I can't use 'find' query, in mongo shell it just returns nothing (empty line). I also can connect to DB without credentials and I see the same result.

I've tried a different roles and different users, but I can't get access to my data. What can be a problem?

Upvotes: 0

Views: 1599

Answers (1)

JJussi
JJussi

Reputation: 1580

OK!

  1. When you login, you need to use --authenticationDatabase -parameter, normal value for that is 'admin'.

mongo host:port -u user -p password --authenticationDatabase admin

  1. If authentication database is not same database where your collection is (your collection is not at admin-database) give that database name as last parameter at 'mongo'-command, to select that DB.

mongo host:port -u user -p password --authenticationDatabase admin myOwnDB

OR

  1. after successful login, use command: 'use your_db_name', to change that database.

use myOwnDB

IF you don't know your database name. When you have login successful, give command 'show dbs' to list all databases.

show dbs

After that you can use command 'use db_name' to change database. Then you can use command 'show collections' to list all collections on that database.

use myOwnDB

show collections

Upvotes: 1

Related Questions