MongoDB installation on Windows - mongodb

I am new to MongoDB and trying to install MongoDB on Windows 8.1.
After I finished the .msi installtion and prompt C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe -dbpath E:\MongoDB\data\dbon CMD command, where the folder E:\MongoDB\data\db has already been created manually.
After I input that command on CMD, it seems that the program stops at [thread1] waiting for connections on port 27017 and does nothing for a long time.
So anyone knows what's wrong and how to fix it?Many thanks.

As stated in this Documentation, the waiting for connections on port 27017 means that mongoDB is running succesfuly(server instance).
You will need to connect to MongoDB through mongo.exe shell using another CMD instance (client instance).
The waiting message in first console would change to connection accepted, and you can start working on your client side.

Related

Why does the mongo shell work without mongod server being explicitly run?

Running MongoDB Shell v-3.2.8
I've noticed that articles and tutorials always mention to run the mongod server before running the mongo shell.
However, when I skip the first step and simply type mongo into my terminal, the mongo shell works without any errors / interruptions.
MacBook:Desktop user$ mongo
MongoDB shell version: 3.2.8
connecting to: test
Why does this work? Does mongo call mongod?
The mongod is being ran as a service or daemon, which means that there is always a mongod process running listening to a port. I use ubuntu, and when I install mongodb through the package manager, it immediately starts up a mongod process and begins listening on the standard port.
Running mongo is simply a small utility that attempts to connect to the localhost at the standard ip. The data reading, writing, and querying is done by the mongod process while mongo is a small program that sends the the commands to mongod.
If mongod wasn't running, you would see an error stating "Unable to connect to mongodb server"
I noticed the same. I think mongoose is doing some smart things there, which I'm not sure how it works. But I have noticed such things before, like mongoose will automatically add an "s" to your database's name when you declare it, which is a very thoughtful act =)).
I encountered the same thing and found that in the background services if MongoDB server is running, the mongo shell will work without any error. If we stop the service, the shell will throw an error.

What are the practical differences between mongo and mongod?

Just finished installing mongodb, however, I have not been able to make complete sense of the difference between mongo vs mongod commands. Yes, I do understand that
mongod is the primary daemon process for the MongoDB system
and that
mongo is an interactive JavaScript shell interface to MongoDB
but what does that mean practically? I presume every time I want to use mongodb, I need to run mongod first. But then why am I able to run mongo without having started mongod first? Does mongo run mongod in the background automatically? Secondly, if I run mongod it eventually ends with something like
waiting for connections on port 27017
but then I can't type anything after that. Again, I presume that mongodb has been started in the background so I can safely close the terminal. But if I close the terminal by mistake (on a mac), how can I get that back up on the terminal? Also, how can I terminate the service for it to stop listening to the port?
So as you can I see, I have a bunch of simple questions... but most are related to the practical uses of when and when not to mongo or mongod. I can't seem to find anything online that will help me explain these in the practical sense.
As with most database software, Mongo is split into a server and client. The server is the main database component which stores and manages data. Clients come in various flavours and connect to the server to insert or query data.
mongod is the server portion. You start it, it runs, end of story.
mongo is a default command line client. You start it, you connect to a server, you enter commands, you quit it.
You have to run mongod first, otherwise you have no database to interact with. Simply running mongod on a command line will make it the frontmost running application, and it does not offer any interactivity. So yes, you'll just see something like "Waiting for connections...", and nothing more. You typically don't run mongod like that on the command line. You most typically create an init.d script or launchd file or however you manage your daemons, and have the system start it automatically at system boot time.
If you want to launch mongod as a one-off thing without having it permanently running on your systems, put it in the background:
$ mongod &
The & puts it in the background and you can continue to use your command line. You can see it and kill it like this:
~ deceze$ mongod &
[1] 1065
~ deceze$ jobs
[1]+ Running mongod &
~ deceze$ kill %1
[1]+ Done mongod
Once your server is running, start mongo, connect to the server, and interact with it. If you try to run mongo without a running server, it should complain that it's not able to connect:
~ deceze$ mongo
MongoDB shell version: 3.0.2
connecting to: test
2015-08-13T09:36:13.518+0200 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-08-13T09:36:13.521+0200 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
If your mongo shell does connect to something, you might unknowingly have another instance of mongod running on your system.
With mongodyou are starting the server on your machine. As you stated correctly, mongo is your client, your user interface, if you want to. Per default it connects to your local instance of MongoDB. If you start your client without a server instance running, you would have to 'tell' it, where it should connect to (e.g. a remote instance):
http://docs.mongodb.org/manual/reference/program/mongo/

Kill MongoDB Server - Windows 7

I just fired up mongod.exe for my first time. However, I accidentally closed the command prompt and now I can't figure out how to kill the DB server process. I tried connecting via mongo.exe but I'm getting following error:
exception: connect failed
How do I stop the server process?
If you started mongod.exe via a command prompt in Windows:
> mongod
And then you closed that command window, the process will automatically be terminated. It is not running any more.
The error you're receiving when running mongo.exe is because MongoDB is not running. You'll need to run mongod.exe again if you need to access the database with the console via mongo.exe
You may want to consider setting MongoDB up as a service on Windows.

Issue with installation of Mongo DB on Windows 8.1

I am trying to install Mongo DB on a windows 8.1 64 bit machine and I a getting the following error.
C:\MongoDB\bin>mongo.exe
MongoDB shell version: 2.4.7
connecting to: test
Tue Nov 19 14:50:02.652 Error: couldn't connect to server 127.0.0.1:27017 at src
/mongo/shell/mongo.js:145
exception: connect failed
Make sure you have the daemon process running. You start it via mongod.exe. You are running the client side and by default connecting to port 27017 - the default mongo instance. Check your running processes for mongod first!
Make sure to unclick the download compass section when you download the shell. As soon as I unclicked it I was able to install the Mongodb shell. Hope this helps - I was stuck with this problem for a long time.

mongo db testing error

I came to know about Mongo db. So I installed it on ubuntu 11.04. To check whether it is installed or not I checked it in software center and it was there. So for test I made command in terminal as
$mongo
but it is something like this
Error: couldn't connect to server 127.0.0.1 shell/mongo.js:79.
so can someone tell me how to solve this problem.
Your mongod is not running. Check the process list using "ps" and restart the mongod service if it is not started.