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]
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.
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.
Explanation. show dbs returns the list of all the databases.
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With