Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo shell not showing databases?

Tags:

mongodb

I have various Mongo databases and when I do ls -l in my CentOS linux I can see the databaseA.0 and databaseA.ns files for each database and the file size is large enough to tell my data is still there, but when I go to the mongoDB shell by executing the mongo command and do a show dbs or show databases it only shows admin(empty), local 0.078GB, and test(empty). How do I get my databases back?

Additonal info: When I start the mongo shell I get the following:

MongoDB shell version: 2.6.4
connecting to: test
Server has startup warnings:
2014-08-15T23:23:14.300-0500 [initandlisten]
2014-08-15T23:23:14.300-0500 [initandlisten] ** WARNING: You are running in OpenVZ which can cause issues on versions of RHEL older than RHEL6.
2014-08-15T23:23:14.300-0500 [initandlisten]
2014-08-15T23:23:14.300-0500 [initandlisten] ** WARNING: /proc/sys/vm/zone_reclaim_mode is 1
2014-08-15T23:23:14.300-0500 [initandlisten] **          We suggest setting it to 0
2014-08-15T23:23:14.300-0500 [initandlisten] **          http://www.kernel.org/doc/Documentation/sysctl/vm.txt
2014-08-15T23:23:14.300-0500 [initandlisten]
like image 326
ConfusedDeer Avatar asked Aug 16 '14 03:08

ConfusedDeer


People also ask

How do I view databases in Mongo shell?

In MongoDB, you can use the show dbs command to list all databases on a MongoDB server. This will show you the database name, as well as the size of the database in gigabytes. You can select any database using the use statement and work on it.

Why my database is not connecting in MongoDB?

If you have created a user and are having trouble authenticating, try the following: Check that you are using the correct username and password for your database user, and that you are connecting to the correct database deployment. Check that you are specifying the correct authSource database in your connection string.

Which of the following command can be used in Mongo shell to show all the databases in your MongoDB instance?

Explanation. show dbs returns the list of all the databases.


1 Answers

Checking the dbpath

I would check the dbpath used by MongoDB is set to what you expect it to be.

In the mongo shell, run:

 db.adminCommand("getCmdLineOpts")

If there is a dbpath set it will be listed there as parsed.storage.dbPath (since you are using MongoDB 2.6). If there isn't an explicit setting the dbpath will default to /data/db.

If a configuration file was used, you should also see a path to the config listed in parsed.config.

To fix the dbpath you need to update the configuration file and restart mongod.

Setting the dbpath

Note that there are two configuration file formats supported by MongoDB 2.6, so you need to match the format of the existing file:

  • YAML configuration - added in 2.6:

    storage:
        dbPath: /var/lib/mongo
    
  • Legacy INI-style config format - still supported in 2.6, and the likely format if you upgraded from an older version of MongoDB

    dbpath = /var/lib/mongo
    

YAML configurations use semicolons for separators, while the legacy format uses equals signs.

like image 129
Stennie Avatar answered Nov 15 '22 04:11

Stennie