Mongo db not start - mongodb

i am new to mongo db. And i do not understand why my monggo db is not starting, and instead it is shutting down.
I have an image below, that shows what is going on at the cmd
cmd, mongo db

Kill all other mongod instance before starting a new instance. The problem is clearly written in the cmd.
Or try to start mongo on another port using
mongod --port 27010 --dbpath c:\data\newDb
Also, make sure you have c:\data\newDb and c:\data\db folders created before starting the server.

Related

Start replSet automatically

I am pretty new to installing MongoDB on Server. It was for a MERN stack project. And in order to use a library Pusher. I need to convert the Stand Alone Server to Replication set.
So I used the script sudo mongod --port 27017 --dbpath /var/lib/mongodb --replSet rs1 --bind_ip localhost,<my server ip> and the terminal will start logging. And then I can use another terminal to access the MongoDB database. But the problem is the moment I close the logging terminal (where I used the --replSet script) I will be prevented from accessing the MongoDB database.
So is there any way to automatically execute the --replSet script as soon as the server starts and keep it running?

Mongodb standalone , listen to CRUD events

I am using standalone Mongodb and want to listen to any CRUD operation performed ,whether by code or done manually in mongo by console/GUI.
I was looking into change stream and mongo stitch , but change streams and mongo stitch are not provided in standalone Mongodb.
It is any event raising mechanism provided in standalone mongodb?
Convert your standalone MongoDB to a single node replica set. In this case, you will still be running with the single MongoDB instance, but instead of running it as standalone you will be running it as a replica set.
Shut down the standalone mongod instance.
Restart the instance. Use the --replSet option to specify the name of the new replica set. For example, the following command starts a standalone instance as a member of a new replica set named rs0.
mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0
Connect a mongo shell to the mongod instance. After connecting run the following command to initiate a replica set.
rs.initiate()
Now, you will be able to make use of the change stream functionality.

How to run multiple mongod instances in windows?

I am trying to run mongod instances on port 27018 and 27019, while port 27017 already running using windows command line. However,I am unable to start as it is terminating saying, already a mongod instance is running. How do i achieve running multiple instances ?
You just need to create another folders
MongoDB2
MongoDB3
dbpath for the second and third instance,
and run it in different port(27018,27019)
The dbPath value controls the location of the mongod instance’s data directory. Ensure that each database has a distinct and well labeled data directory.
Also Refer doc
mongod --dbpath /usr/local/var/MongoDB2 --port 27018

MongoDB: Custom Port & DB Path Not Working

I have a new MongoDB server that I want to run with a custom port + db path.
I made these edit in my /etc/mongod.conf:
port = 53214
dbpath=/var/lib/mongodb
I can confirm the dbpath exists and is owned by the mongodb user.
But, when I try to start mongod (service mongod start), it wants to use port 27017 and dbpath /data/db.
I tried deleting mongod.lock in /var/lib/mongodb, but that didn't help.
My question:
Do I have to manually pass these parameters each time I start mongod?
mongod --dbpath /var/lib/mongodb --port 53214
If so, what's the point of the config file?
It turns out you need to pass in the config file, like this:
mongod --config /etc/mongod.conf

Mongodb problem_could not connect to server

I use ubuntu 14.04LTS and with mongodb version 2.4.9.When I type "mongo" in terminal, it always show "connecting to: test
Tue Jun 3 10:03:57.911 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed".
But if i run mongod in one terminal, and run mongo in another, all is ok.
If I close the window of mongod, the connection fail again.
I need to use mongodb without open a terminal of mongod, how can I do with it ?
Thank you!
You need to start mongodb as a service or daemon(depending on the OS,in your case daemon), check the documentation
Documentation
sudo service mongod start
Or
To run a mongod process as a daemon (i.e. fork), and write its output to a log file, use the --fork and --logpath options. You must create the log directory; however, mongod will create the log file if it does not exist.
The following command starts mongod as a daemon and records log output to /var/log/mongodb.log.
mongod --fork --logpath /var/log/mongodb.log