Installation process in MongoDB database - mongodb

installation error while starting my mongodb server..
Ensure the user executing mongod is the owner of the lock file
and has the appropriate permissions. Also make sure that another
mongod instance is not already running on the C:\\data\\db\\ directory
how to start a server in my windows mongodb version--6.0.3

Related

Mongod vs MongoDB server running as windows service

I am trying to find out what is the difference when i start mongod db with mongod command vs starting mongo db server as a windows service.
I tried starting the server using mongod and inserted some records then i tried starting mongo db via windows service and inserted some records, results are different in the same database
You are using two different databases.
And you likely checked the "install mongod as a service" in the installation.
The mongod command directory is, by default, C:\data\db.
If you setup your mongod Windows service directory to any other directory, this means you potentially have two databases (data folder).
You can search for the file named mongod.lock. If you find the file on different directory. you have more than one mongo database.

How to execute 'service mongod start' using additional parameters in CentOS?

I unable to start MonogoDB service after adding users into admin db as well as my db.
I setup MonogoDB and started service using following command i.e.
service mongod start
Using command prompt, I added few users like dbOwner, clusterAdmin, readWrite, read roles base users. Along with that I also changed configuration from /etc/mongod.conf. in that file, I changed port number, IP addresses, dbPath, and security.authorization: enabled.
Then I restarted mongod service using following command.
service mongod restart
After ran this command, mongod service stopped successfully, but failed to start with only 'FAILED' message.
I tried execute following command i.e.
mongod --port 27123 --dbpath /path/to/db --auth
It is working.
Question: How to execute 'service mongod start' using additional parameters in CentOS?
MonogoDB: 3.4
OS: CentOS 7
I got solution i.e.
mongod --config /etc/mongod.conf
Referred: https://docs.mongodb.com/manual/reference/configuration-options/#use-the-configuration-file
It starts child process and also I can stop mongod service using service mongod stop command.
But I don't know whether it is correct or not.
I can't certify exactly where the script that "service" command uses on CentOS 7, but in Ubuntu 18.04 mongod service script file is in
/lib/systemd/system/mongod.service
There you can change the user who executes the process and add any parameters you want, like --auth.
Said that, if you ever executed mongod as root, some files on where you store the db data will have the owner as root, making the database fail to start as another user. The fix I found for that is to manually chown to mongodb:mongodb (or the user you want to use) all the files that are owned by root inside the database.
Hope this helps.
mongod.service file from mongodb github

MongoDB - mongo command runs but mongod doesn't

I have a MEAN droplet on digital ocean and I've found that when I run the mongo command I connect to test successfully and have access to my other databases, but if I try to run the mongod command I get the following message:
*********************************************************************
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
How is this possible? I thought mongo was connecting to a specific instance of mongod.
I will create the /data/db folder, but I feel like I might just be ignoring another problem with setup configuration that has allowed this to happen.
/data/db will be the place you store your database data. After you created that folder, you can run mongod as normal.
The mongod is a command to start mongodb server. And mongo is a command line interface to make you community with mongodb server.
So you should start the server -> community with server.

Issue with persistent mongoDB data on EC2

I'm trying to store data in a mongoDB database on Amazon EC2. I'm using starcluster to configure and start the EC2 instance. I have an EBS volume mounted at /root/data. I installed mongoDB following the instructions here. When I log in to the EC2 instance I am able to type mongo, which brings me to the mongo shell with the test database. I have then added some data to a database, let's say database1, with various collections in it. When I exit the EC2 instance and terminate it, using starcluster terminate mycluster, and then create a new, different instance, the database1 data is no longer shown in the mongo shell.
I have tried changing the dbpath in the /etc/mongodb.conf file to /root/data/mongodb, which is the EBS volume, and then start and stop the mongodb service using sudo service mongodb stop and sudo service mongodb start. I then try mongo again and receive
MongoDB shell version: 2.2.2
connecting to: test
Sat Jan 19 21:27:42 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
An additional issue is that whenever I terminate the EC2 instance any changes I made to the config file disappear.
So my basic question is: how do I change where mongoDB stores its data on EC2 so that the data will remain when I terminate one EC2 instance and then start another EC2 instance.
Edit:
In response to the first answer:
The directory does exist
I changed the owner to mongodb
I then issued the command sudo service mongodb stop
Checked to see if the port is released using netstat -anp | grep 27017. There was no output.
Restarted mongodb using sudo service mongodb start
Checked for port 27017 again and receive no output.
Tried to connect to the mongo shell and received the same error message.
Changed the mongodb.conf back to the original settings, restarted mongodb as in the above steps, and tried to connect again. Same error.
The EBS volume is configured in the starcluster config to be reattached on each startup.
For the "connect failed" after you change /etc/mongodb.conf problem, you can check the log file specified in the /etc/mongodb.conf (probably at /var/log/mongodb/mongodb.log):
Check that the directory specified by dbpath exists.
Make sure it is writable by the "mongodb" user. Perhaps it's best to chown to mongodb.
Make sure mongod actually released the 27017 port before starting it using: netstat -anp | grep 27017
Wait a couple seconds for mongod to restart before launching mongo.
It's not clear from your question if you are using Starcluster EBS volumes for Persistent Storage. Note that Ordinary EBS volumes do not automatically persist and reattach when you terminate an instance and start another. You would need to attach and mount them manually.
Once you get that working you'll probably want to create a custom Starcluster AMI with mongo properly installed and /etc/mongodb.conf appropriately modified.

Moved Mongo Database to Different Drive: Unable to acquire lock for lockfilepath

I am in the process of moving my mongo data to a different drive. All of the data I want to move is stored in /data/db and I am moving it to a NAS (Network attached storage).
First step:
mongodump -d mydb -c mycollection -o nas/mongo-temp
This created a file tree in mongo-temp/ like so:
dump
`-- mydb
`-- mycollection.bson
1 directory, 1 file
I then stopped the mongod service and created a new /data/db directory:
/etc/init.d/mongod stop
mkdir mongo-temp/data/db
...and changed the dbpath line in /etc/mongodb.conf
dbpath=.../mongo-temp/data/db
I successfully restarted the mongo server using /etc/init.d/mongod start.
When I try to connect:
mongo
MongoDB shell version: 1.6.4
Thu May 3 09:53:23 *** warning: spider monkey build without utf8 support. consider rebuilding with utf8 support
connecting to: test
Thu May 3 09:53:24 Error: couldn't connect to server 127.0.0.1 (anon):1154
exception: connect failed
I've tried to start mongod with the command mongod --dbpath .../mongo-temp/data/db but I get an error that says:
Thu May 3 09:57:26 exception in initAndListen std::exception: Unable to acquire lock for lockfilepath: /home/dlpstats/nas-mnt/mongo-temp/data/db/mongod.lock
Removing the lockfile doesn't help. If I run the mongod command without --dbpath, the server starts fine and I am able to make queries on my old database.
First, you mentioned that you used mongodump to populate the new drive - was this just a method of backing things up or did you intend that to be the new database files? That is not how it works - mongodump output is not the same as a database file - it needs to be re-imported with mongoresore in fact. If you do a straight data file copy then the transfer will be seamless.
Then, as well as the permissions suggested by Wes in his answer, a few more things to check:
That you have shut down the old server successfully and completely - it's possible it's mis-reported error and you are getting it because it is trying to grab a port that is already open
You are using version 1.6.4 according to the mongo shell output, my guess is that you installed from the Ubuntu repo for 11.04 or similar, that is not a good option - 1.6 is very old at this point. Use the 10gen repos (http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages) or download the binaries and get a more recent version
Last but not least, when you start the mongod manually, make sure all the arguments are the same, like the port. When you connect via the mongo shell, specify the port you started the mongod on - don't rely on defaults when running into issues like this, be explicit.
I faced this problem and issuing following command solved my problem:
rm /var/lib/mongodb/mongod.lock
And then restart the mongod.
But I'm not sure is it a good solution or not.
Check the permissions for the directory and parent directories of mongo-temp. Presumably it's running as the mongodb user?
You need execute permissions on the directory (and parent directories) in order to create files there. Execute permissions on a directory allow you to list the files there, which is needed to be able to open the file for writing.