mongod --datapath can't read collections from copied data folder from another pc - mongodb

My windows crashed so I copied the data folder of mongodb which I used to run mongod --datapath "C:/data" to another PC.
But when I run mongod --datapath "C:/data", I can't see my old collections.
How can I make it ?

Sorry everyone. I remember that my dbpath is /data/db and the log path is /data/log. Not a /data for all. Thanks

Related

IllegalOperation: Attempted to create a lock file on a read-only directory MongoDB in ubuntu 20.04

I have just installed mongodb on my remote ubuntu server for using it with an angular and nodejs project. I created a user using the db.createUser command along with password and roles in the mongo shell.
Then when i try to start the mongodb instance with access control using the command:
mongod --auth --port 27017 --dbpath /var/lib/mongodb
its displaying the error:
IllegalOperation: Attempted to create a lock file on a read-only directory MongoDB
First of all, have you checked the permissions of the folder /var/lib/mongodb (ls -l /var/lib)?
The folder and its contents should be assigned to the mongod user. You could also check the ACL permissions (getfacl), if that's installed in your system.
If permissions seem correct, please continue reading to know how I solved the same error in a different environment.
This happened to me in CentOS 8 after a wrong reinstallation of MongoDB and the data folder /var/lib/mongo had to be created manually. In my case, the problem was that the security context of SELinux (https://www.redhat.com/en/topics/linux/what-is-selinux) had to be updated to give mongod access the folder.
The command below solved my problem (note the path to the data folder in my configuration is slightly different, just update it for your case):
chcon -Rv --type=mongod_var_lib_t /var/lib/mongo
It basically tells SELinux that the context used by MongoDB to access the files should be associated with the target folder.
You can have more information about chcon here: https://www.man7.org/linux/man-pages/man1/chcon.1.html

Running an instance of mongod from terminal ends with "[initandlisten] shutting down with code:100"

I've been searching for an answer for a week now and haven't found out how to keep this from happening. I currently have mongo stored from my root directory into a file with path /data/db. The contents of this directory after typing ls...
Contents of /data/db
After I run the command mongod I see this...
After running mongod
I've installed mongodb with homebrew and have followed the installation rules over and over after installing and uninstalling thinking I made a mistake. I'm stuck and am new to mongodb altogether. I've noticed that Homebrew is installed in /usr/local/ and I believe mongo is stored in /data/db/.
I think there is some permission issue. Try changing the group and owner of the directory and the directory where socket file is being created through the command
sudo chown mongo User:mongo User data/socket directory

MongoDB not logging to log file

I'm using MongoDB on OSX, with mongod confirmed running. I checked the mongod.conf file and the following is present and unmodified:
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
So far so good. The path location exists, however the folder is empty - no mongo.log. This was a standard installation and everything has been fine so far except this. Any idea on how to troubleshoot this issue?
Context
I deleted my mongod.log file once. Then I recreated it and ran into this exact problem. I may have deleted the /var/log/mongodb folder as well, then recreated it.
I was reading under Run Mongodb Community Edition:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
The MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb by default, and runs using the mongodb user account.
I read into this way too much and assumed the user who starts the mongodb service is the "mongodb user account". This is incorrect. They literally mean the user: mongodb
Solution
sudo chown mongodb /var/log/mongodb

How can I access copied mongodb folder

I just got copied database folder(literally copy and paste) of mongodb.
Actually, I'm beginner of mongodb and have a lot of problem to access copied database.
Could you give me any advice?
To start the database with the new directory - you can do the following:
Change dbpath in config: link, then restart mongod service
Run single mongod instance like "mongod --dbpath /data/db".
If you use WireTiger engine - "mongod --dbpath /data/db --storageEngine wiredTiger"

MongoDB Path Change?

My server went down from an electrical failure and for a few horrifying seconds, I thought I'd lost all MongoDB data. I then realized that when the server restarted, mongo automatically restarted without the --dbpath option.
What I can't figure out is why, even though my mongodb.conf has the dbpath set to /var/lib/mongodb, mongo looked for the db files in /data/db on startup. Can anyone shed some light on this?
Thanks!
/data/db is the default path that mongod will look for data files in if it is started with no options. Does your startup script instruct mongod to load the correct config file? If not, that would explain this behavior.
When was the last time you updated Mongod on your system? and how did you update it?
Depending how you installed / updated Mongod it could happen that either the /etc/init.d/mongo script or the /etc/mongo.conf files could be overwritten.
Or somebody edited those files a long time ago, and this is the first time Mongo got restarted, and now it looks like there's suddenly a change.
I haven't seen either of those two things happen in a long time (but if you're using Gentoo, you would probably see this happen)
What OS do you use?
It's a good idea to keep backups of those files...
You should definitely ensure that your init script for Mongo includes the full pathname to the data directory. Here is a snippet of what we use in our production deployment:
ulimit -s unlimited
MONGO_USER=mongo
MONGO_HOME=/opt/mongo
MONGO_DATA=/san2/data
MONGO_LOGS=/home/mongo/logs
start() {
su $MONGO_USER -c "$MONGO_HOME/bin/mongod --master --fork --logpath $MONGO_LOGS/mongodb.log --logappend --dbpath $MONGO_DATA --maxConns 2400"
}
Check the startup options in /etc/default/mongodb most likely those will be set to the default path of /data/db instead of the one you selected when you started it up manually.