Recovering mongodb `--dbpath` - mongodb

I used MongoDB a month ago to run a simple web app to collect data for my research. After some inactivity (during which I did not run MongoDB), I forgot the parameter dbpath. Now, whenever I launch mongod on my Mac, I get the error, which I understand:
Exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
I have tried:
Reading mongodb.conf (apparently that's not the correct path; I think it got reset.)
Looking into all my terminal history.
I do know the name of the collection and the database. And that my database was password protected.
I have already read most of the answers including this:
Forgot mongodb data path

Related

MongoDB WiredTiger error: WiredTiger.turtle: handle-open: open: operation not permitted

MongoDB was working beautifully for me for several months until I had an unexpected shutdown a week or two ago. Since then, I've been getting the error in the title that snowballs into an invalid argument, then a library panic, then some fatal assertions which cause MongoDB to crash.
Now, I've done my research: the normal answers are to run the repair function and to make sure SELinux isn't screwing up the process. Neither of those have worked. The error gets thrown during WiredTiger's checkpoint process, so reads/writes to the database aren't the issue, and because it's during the checkpoint process, it guarantees that MongoDB won't stay up for more than a day.
To be clear: all the files in the database are owned by mongod:mongod, have permissions set to 600 (default, and I tried setting them to 755 to see if that fixed it, and it didn't). I'm running mongodb as a service on a CentOS 7 box, and the service file specifies that it should run as user mongod. The mongod.conf file specifies a mounted filesystem as the database, and it was happy with that until the unexpected shutdown. I'm running MongoDB version 4.0.1, so WiredTiger really doesn't like it if I disable Journaling either (disregarding the fact that I shouldn't disable it in the first place).
I feel like I've exhausted all my options, and that the only thing I can do is backup my data and reinstall MongoDB. Are there any that I've missed?
After creating a backup of my data via mongodump, shutting down mongo, removing the entire database with rm -rf 'path-to-database', rebooting mongo (without the replication config), and restoring the data with mongorestore, mongodb still crashes. This time, however, it's with an Invariant failure after the open: operation not permitted. The only conclusion I can think of is that the data itself has become corrupted in some way. Thankfully, this isn't "mission critical" data, so to speak, and I can easily obtain new data.
Unfortunately, this doesn't answer my original question of "what other options do I have?". However, I'm still posting this in case others run into this same kind of issue.
EDIT: invariant issue was caused by me forgetting to re-initialize my replication set. After fixing that, it's clean. Because of this, I no longer believe it was a data corruption issue, but a checkpoint corruption issue.
EDIT 2: So the issue arose again after about a week, and after another week of trying various debugging methods, I tried simply moving the mongo process to another server. So far, that's been working. The previous server was acting up (I couldn't even run top at one point - another process had a lock on a necessary library file to run it), so here's to hoping that the current server doesn't follow suite.

WriteConcern detected an error in mognodb

When I am saving documents in monogdb, getting the following error
"{WriteConcern detected an error 'bad offset:0 accessing file:xxxx - consider
repairing database'. (Response was { \"err\" : \"bad offset:0 accessing file:
xxxxx - consider repairing database\", \"code\" : 13440, \"n\" : 0,
\"connectionId\" : 13, \"ok\" : 1.0 }).}"
any help please
As the error states, the database requires repairing because it is in an inconsistent state due to whatever operation that caused unexpected shutdown.
In MongoDB WriteConcern provides feedback/acknowledgement in response to a write operation. There are multiple levels of WriteConcerns or guarantees that on whether the write operation was successful or not. The WriteConcerns levels are as follow:
Unacknowledged (the client does not wait for acknowledgement of write op)
Acknowledged (client waits for success or exception ack. of write op)
Journaled (mongodb sends acknowledgment only after committing the write to journal)
Replica Acknowledged (ack. of write op on primary and/or other members of replica set)
You can set the levels of WriteConcerns to any level depending on importance of write operation.
The WriteConcern in your case returns an exception stating that database is in an inconsistent state may/may not data might have been corrupted. In order to get back to operational mode, you need to repair the database in one of many ways.
Via Mongodb shell (if you can connect to MongoDb)
Via command line with mongod see below
If you can get into MongoDB shell, then you need to find the database and repair it as follow
use dbName
db.repairDatabase() //repairs the above database
If you cannot get into MongoDB shell or wish to use other method then you can use the following methods
Repair Data files and preserve original files
mongod --dbpath /data/db --repair --repairpath /data/db0
mongod --dbpath /data/db0
Once the first command above complete, the newly repaired data will be under /data/db0 directory and you can use the second command to start mongodb using repaired data. The original data files are preserved in the default /data/db or a custom location (if not default)
Repair Data files WITHOUT preserve original files
This method you only supply --repair and no --repathpath and it will attempt to repair the original data files. First you have to delete mongod.lock file, steps are as follow:
rm /data/db/mongod.lock
Assuming your data is in /data/db directory, if not specify the location.
mongod --dbpath /data/db --repair
Start mongod with only --repair option, you don't have to pass --repairpath option. This will attempt to repair the data. Then finally start the database
mongod --dbpath /data/db
If you follow the first method of repair then you can delete the mongod.lock after the repair is successful. If you follow the second method then you can delete he mongod.lock before performing the repair operation.
Read the documentation how to safely shutdown the database, what is in mongod.lock? How you should do the repair (for example running it with same user in order to preserve the file ownership). It is also possible that the permissions to your data files has changed, you can chown them back, see this question for more details.

Connection to MongoDB fails

I tried to connect to a local MongoDB instance, but it failed with error message Failed to connect.
I have run the commands shown in the below screenshots. The error message is shown there, too.
My folder structure is:
D:/mongodb/bin
D:/mongodb/data/db
D:/mongodb/log
I am using 32-bit Windows7.
Your data directory doesn't exist where MongoDB is expecting it to be.
For simplicity you can create D:/data/db, which is the default location and where mongod is looking at the moment, and use this as your data directory.
Alternatively if you want to use D:/mongodb/data/db as the data directory you'll need to specify the dbPath when starting mongod
mongod --dbpath D:/mongodb/data/db
This can also be done in a configuration file.

mongodb DBException

Any clue on this exception?
[conn1026] DBException in process: could not initialize cursor across
all shards because : can't map file memory #
set1/192.168.1.1:27018,192.168.1.2:27018,192.168.1.3:27018
this is happening after I lost some mongoD instances and they are up again..
So I figured what was the problem.
In that set1, the second machine had a file database files were owned by root and not by mongodb user. Dont ask me why this was like that, anyways, I just changed the permissions on those files and everything was back to normal..

Is it normal for MongoDB whole /data/db to be gone after a electric trip that result in crash

I have a single machine that has MongoDB and its data is at /data/db as usual.
When my machine crashed due to an electric power trip, my MongoDB refuse to start at launch (Mac OS X Server via LaunchAgent) and also /data/db mysteriously disappear!
Also all log file are wipe out. This happen on my development SSD MBA and I thought is just a weird SSD case. But my XServe server is getting it as well when the power trip.
Am I missing some data protection articles somewhere? For sure it can't be this unreliable by just deleting /data/db!!??
MongoDB will never ever remove your database files!
In case of a crash you have to start mongod using the --repair option.
In addition: using the new journaling option of MongoDB in V 1.8+ that should help a lot when you run MongoDB as standalone service.
No that is not normal.
If it won't start, it's likely mongodb is indicating that you need to run a repair because mongod.lock is present and has a certain state in /data/db. But that would mean /data/db exists.
If /data/db exists but were empty (which in this case would be bad obviously), it would start right up.
If you log(s) are missing, sounds like a more general disk issue.
So check the startup message if about mongod.lock there is data there. Also with v1.8+ use journaling. (albeit you wouldn't lose all datafiles even without journaling)