Difference between "mongo" and "mongod"? - mongodb

I've installed MongoDB and I've found some unlogical things and I hope someone will answer me:
When I execute "mongo" I get logged into shell
When I execute "mongodb" I get the following errors:
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] MongoDB starting : pid=7221 port=27017 dbpath=/data/db 64-bit host=debian
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] db version v3.2.7
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] git version:
4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] modules: none
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] build environment:
2016-06-23T22:58:39.302+0000 I CONTROL [initandlisten] distmod: debian71
2016-06-23T22:58:39.303+0000 I CONTROL [initandlisten] distarch: x86_64
2016-06-23T22:58:39.303+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-06-23T22:58:39.303+0000 I CONTROL [initandlisten] options: {}
2016-06-23T22:58:39.325+0000 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2016-06-23T22:58:39.325+0000 E NETWORK [initandlisten] addr already in use
2016-06-23T22:58:39.325+0000 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-06-23T22:58:39.325+0000 I CONTROL [initandlisten] dbexit: rc: 48
What is the difference between two terminal commands: mongo as a first, and mongodb as a second?
MongoDB is great because my project is schema-less but it's always a horrible experience to configure it, create roles, authorization etc.
Thanks.

mongod is the server, to which requests to connect database are passed for example.
In above error, it shows that port address 27017 is in use. It means your mongod is already runnning. You just need to run command 'mongo' to access the Mongodb shell.
There is another possibility that some other process is running on port 27017
netstat -n | grep 27017 to check if process is running and kill -9 $(lsof -ti:27017)'

To use any database service, you have to start the database Server and same is the case with mongodb, the command mongod is used to start the MongoDB Server on your local machine or server.
In your question you have asked for the command mongodb that's not correct you need to run command mongod, 'b' is not the part of this command.
When you run the mongod, it starts your mongodb server on default
port 27017.
Then you open another terminal and use the command mongo to enter
into the mongo shell and perform your database operations.
The difference between the both commands is that mongod starts the
mongodb server and mongo allows you to enter into mongo shell to
perform further database operations.
Also, when you install mongodb, you have an option to install it as a service. Installing mongodb as a service starts the mongodb server in background when you boot your system.

Related

WARNING: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted

I am completely new in developing and just have installed mongoDB with the help of ducumentation provided by mongodb.com
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
After entering mongod in the console.it shows waiting for connections on port 27017...which is ok
but when I open a new tab and enter the command :- mongo
I show various Warning
WARNING: Access control is not enabled for the database.
2020-07-01T15:17:26.709+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-07-01T15:17:26.709+0530 I CONTROL [initandlisten]
2020-07-01T15:17:26.709+0530 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2020-07-01T15:17:26.709+0530 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2020-07-01T15:17:26.709+0530 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2020-07-01T15:17:26.709+0530 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2020-07-01T15:17:26.709+0530 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2020-07-01T15:17:26.709+0530 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
It is a security warning we put in the mongo shell to prevent you accidentally creating a MongoDB cluster with no access controls and then watching in dismay as the Internet deletes all your data or worse.

MongoDB - shutting down with code 48

I am trying to start MongoDB but the terminal returns the following error:
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] MongoDB starting : pid=25184 port=27017 dbpath=/data/db 64-bit host=Janiss-MacBook-Pro.local
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] db version v3.4.1
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] allocator: system
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] modules: none
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] build environment:
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] distarch: x86_64
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-02-06T16:26:27.037+0000 I CONTROL [initandlisten] options: {}
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] addr already in use
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] Failed to set up sockets during startup.
2017-02-06T16:26:27.038+0000 E STORAGE [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets
2017-02-06T16:26:27.038+0000 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-02-06T16:26:27.038+0000 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-02-06T16:26:27.039+0000 I CONTROL [initandlisten] now exiting
2017-02-06T16:26:27.039+0000 I CONTROL [initandlisten] shutting down with code:48
I am using Laravel Valet if that matters.
It seems like you have already a process running on the port where you want to start mongodb:
listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] addr already in use
you could try to kill the process that runs on that port with this command:
sudo kill sudo lsof -t -i:27017
or define another port for mongodb if you have another program using that port.
to run mongodb on a port other than its default port (27017) use the --port 27018 argument when starting mongodb from the terminal
If you are using mac then you can simply kill the process running on port 27017 which is mongodb process in most cases.
Simply run the command.
npx kill-port 27017
After that you can run the mongod command as you normally do.
Or if you are using windows follow these steps
Run command line as Admin
netstat -ano | findstr :27017
you will get pid in the end that is the process id to kill
taskkill /PID <typeyourPIDhere> /F
after successful termination of process you can run mongod as you usually do!
Enjoy!
This has worked for me
Initially i was facing various issues, like when i tried to start the server by using:
sudo mongod
then i changed port for mongodb
sudo mongod --port 27018
Now mongod server is running tentatively
sudo mongod
Basically you just need to force quit the mongo, you can do this just by typing
sudo pkill -f mongod
and now you can start the server again with
mongod
For me the kill process did not work. Probably because my mongo instance was running on AWS. So, what I did was log onto a mongo shell. (This was possible as mongo instance is running) And switched to the admin DB thru 'use admin' and did 'db.shutdownServer()'. And that shut down the server cleanly
use admin
db.shutdownServer()
I had the same issue (MongoDB failed to start with exit code 48) after a reboot, as it could not bind to the given IP.
It turned out, that the mongod systemctl unit file was configured to launch the mongod service after the network.target. I changed this to network-online.target and it seems to work.
1.And if the mongod show error (shutting down with code 48) that
means the port is being already use so you can do two things
1.a Either you change the port of mongod by specifying port
number
mongod --dbpath /System/Volumes/Data/data/db (path of db) —port 27018
1.b Or You can kill the process at that port by finding
the process by
sudo lsof -i :27017
and then kill by command
kill -9 <PID>
2.Starting mongo db using brew services run mongodb-community
3.Type mongod or mongod --dbpath /System/Volumes/Data/data/db(path)
How I solved my issue?
I don't know the actual reason for this error and its solution but I deleted mongodb database folders C:\data\db and restarted my PC.
2017-02-06T16:26:27.038+0000 E NETWORK [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017.
It means the server 27017 is already in use.
You can try mongod --dbpath /System/Volumes/Data/data/db --port 27018.
Or
You can first stop the mongod by sudo pkill -f mongod.
Then restart the server by mongod --dbpath /System/Volumes/Data/data/db
In some cases we may be unaware of the process id where we have initiated mongodb , and we are not able to track it, as we might have forgot to shut it down in such cases:
step 1: first of all try to know the process id where it is being established, and
to know that, type below code in terminal:
lsof -i | grep 27017
Once you type the above code, you will be able to see process id's using your mongodb server:
enter image description here
As you can see in the above picture, there you can find that "9663" is the process id where your mongodb server is active.
Step 2: Now we need to kill this process, by typing the command:
kill <pid>
In the above code pid stands for process id, as shown in the above image the process id looks similar to that of "9336".
Step 3: Now we have successfully killed the process and then we are good to start
the server of mongodb using the command:
mongod
Now you are good to go!

Cannot connect Robomongo using MongoDB docker image

I am running mongo docker image that I pulled from docker hub mongo image
It works ok but when I start Robomongo I cannot connect to localhost. With following error message:
Cannot connect to the MongoDB at localhost:27017.
Error:
Network is unreachable
I appreciate any help, thanks.
EDIT: I solved the issue by using the following command:
docker run -p 27017:27017 --name mongo_instance_001 -d mongo
Don't forget to map port to host port:
docker run --name some-mongo -p 27017:27017 -d mongo
Then
docker-machine ip
gives me 192.168.99.100
Type in terminal
mongo 192.168.99.100
prints
MongoDB shell version: 3.2.4
connecting to: 192.168.99.100/test
Server has startup warnings:
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten]
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten]
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-22T07:35:20.214+0000 I CONTROL [initandlisten]
I also tested with robomongo. I can connect without a problem.
you can find docker-machine ip just typing this command
docker inspect
container id is sha256

Problems on migrating Parse.com app to AWS EC2 Ubuntu

I have an EC2 machine with Ubuntu installed on it. On the machine, I have installed Node.js, MongoDB, and Github version of Parse Server.
I have created a database called euro. In this database, I've created a user using this code:
> use euro
switched to db euro
> db.createUser(
... {
... user: 'username',
... pwd: 'password',
... roles: [ { role: 'readWrite', db:'euro' } ]
... }
... )
Before migrating the app, I have noticed that in AWS EC2 Instances Managment page, you can see 2 IPs addresses: Public IP and a Private IP, so I used the Public IP.
In the Parse.com settings, I've clicked at the Migrate button, and entered this address:
mongodb://username:password#<ipaddress>:27017/euro
and below the address field, it was written No reachable servers.
What can I do in order to solve it and to migrate the app to my EC2 Instance?
EDIT #1:
I have restarted my AWS server, so my Public IP address has been changed. I've tried to change my connection string to the new IP using this address:
mongodb://username:password#<ipaddress>:27017/euro
But suddenly it shows No reachable servers.
What should I do in order to solve this problem? I want to migrate it as soon as possible.
EDIT #2:
I've checked this command sudo netstat -pan | grep mongod to check on which IP it is listening and I got this output:
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 10945/mongod
tcp 0 0 127.0.0.1:27017 127.0.0.1:45406 ESTABLISHED 10945/mongod
unix 2 [ ACC ] STREAM LISTENING 28614 10945/mongod /tmp/mongodb-2
Is it listening on the Public IP? Private IP? localhost?
I solved it using MongoDB guide and this answer.
The problem was some warnings that I got when I've started the server. Apperently It had prevented Parse.com from connecting to my MongoDB.
$ mongo
MongoDB shell version: 3.0.11
connecting to: test
Server has startup warnings:
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten]
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten]
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-04-01T07:28:10.926+0000 I CONTROL [initandlisten]
>
I wasn't able to solve it because I used this command $ service mongod restart without root permission. I was supposed to use this command $ sudo service mongod restart.

mongo - couldn't connect to server 127.0.0.1:27017

I am coming from riak and redis where I never had an issue with this services starting, or to interact.
This is a pervasive problem with mongo and am rather clueless. Restarting does not help.I am new to mongo.
mongo
MongoDB shell version: 2.2.1
connecting to: test
Fri Nov 9 16:44:06 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
This is what I see in the logs.
now open)
Fri Nov 9 16:44:34 [conn47] end connection 10.29.16.208:5306 (1 connection now open)
Fri Nov 9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5307 #48 (2 connections now open)
Fri Nov 9 16:45:04 [conn48] end connection 10.29.16.208:5307 (1 connection now open)
Fri Nov 9 16:45:04 [initandlisten] connection accepted from 10.29.16.208:5308 #49 (2 connections now open)
Fri Nov 9 16:45:04 [conn49] end connection 10.29.16.208:5308 (1 connection now open)
Fri Nov 9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5316 #50 (2 connections now open)
Fri Nov 9 16:45:34 [conn50] end connection 10.29.16.208:5316 (1 connection now open)
Fri Nov 9 16:45:34 [initandlisten] connection accepted from 10.29.16.208:5317 #51 (2 connections now open)
Fri Nov 9 16:45:34 [conn51] end connection 10.29.16.208:5317 (1 connection now open)
Fri Nov 9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5320 #52 (2 connections now open)
Fri Nov 9 16:46:04 [conn52] end connection 10.29.16.208:5320 (1 connection now open)
Fri Nov 9 16:46:04 [initandlisten] connection accepted from 10.29.16.208:5321 #53 (2 connections now open)
Fri Nov 9 16:46:04 [conn53] end connection 10.29.16.208:5321 (1 conn
Normally this caused because you didn't start mongod process before you try starting mongo shell.
Start mongod server
mongod
Open another terminal window
Start mongo shell
mongo
Resolved.
This problem could be solved by the below mentioned 4 steps
1) Remove .lock file
sudo rm /var/lib/mongodb/mongod.lock
2) repair the mongodb
mongod -–repair
3) start the mongod server
sudo service mongod start
4) start the mongo client
mongo
For more details take a look at http://shakthydoss.com/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/
http://shakthydoss.com/technical/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/
This method only works if you want to repair your data files without preserving the original files
To find where you dbpath resides- vim /etc/mongodb.conf
check for option dbpath=
(I have dbpath=/var/lib/mongodb)
Default: /data/db/
Typical locations include: /srv/mongodb, /var/lib/mongodb or /opt/mongodb .
Replace the /var/lib/mongodb with your dbpath
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --dbpath /var/lib/mongodb/ --repair
sudo mongod --dbpath /var/lib/mongodb/ --journal
(Make sure that you leave you terminal running in which you have run above lines,
dont press 'Ctrl+c' or quit it.)
Type the command to start mongo now in another window.
Hope this works for you !
for those who want to repair your data files while preserving the original files
mongo recover
This error is what you would see if the mongo shell was not able to talk to the mongod server.
This could be because the address was wrong (host or IP) or that it was not running. One thing to note is the log trace provided does not cover the "Fri Nov 9 16:44:06" of your mongo timestamp.
Can you:
Provide the command line arguments (if any) used to start your
mongod process
Provide the log file activity from the mongod startup as well as
logs during the mongo shell startup attempt?
Confirm that your mongod process is being started on the same
machine as the mongo shell?
I am a windows user and I installed MongoDB in November 2018 and I didn't wanted to setup data/db directories. But after few days, when I open, got an error message:
MongoDB shell version v4.0.4
connecting to: mongodb://127.0.0.1:27017
2018-12-05T20:42:40.108+0530 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:257:13
#(connect):1:6
exception: connect failed
Then I tried to fix using all of above answers and didn't worked. When I tried to run mongod it said
MongoDB starting : pid=12220 port=27017 dbpath=C:\data\db\ 64-bit host=bla
I tried to change the db path(to program files) through file system and also using cmd but those didnot worked.
Solution that worked for me is:
Opened the Task Manager (ctrl + shift + esc) -> Services tab and there was a MongoDB row with the status stopped. Then I right clicked and clicked start and everything working perfectly :).
MAC OS
Check status
brew services list
Something like:
Name Status User Plist
mongodb stopped
start it
brew services start mongodb
Try it again
mongo or mongo --port 27017
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it.
This error caused because Mongo Server been closed
Simple Follow these steps
Open Task Manager
Go to >Services
Find MongoDB
Right click and select Start
In my case:
First I open config file
sudo vi /etc/mongodb.conf
Comment IP and Port like this
#bind_ip = 127.0.0.1
#port = 27017
Then restart mongodb
sudo service mongodb restart
sudo service mongod restart
Finally, it's work :D
finn#Finn ~ $ mongo
MongoDB shell version: 2.4.9
connecting to: test
> exit
A little to late with the answer but I've encountered the same issue
Following are the steps which helped me.
Go to C:\
Create "data" folder
In "data" create "db" folder
open terminal (CMD) -> go to EX:"c:\MongoDB\Server\3.4\bin"
type in mongod => this will start mongo server (leave it opened)
Run using a GUI, EX "robomongo"
Or
open new terminal (CMD) -> go to EX:"c:\MongoDB\Server\3.4\bin"
type in "mongo" command
Make sure that your mongo is running.
I fixed this problem by trying to repair the mongodb, there I found that the directory required for the db to run was not created. It shows this error
Type: mongod, it will show the error
exception in initAndListen: 29 Data directory /data/db not found., terminating
Error happen because dbpath /data/db/ (default config) does not exist. You need to create data folder and set permission for it.
Then I create a folder on my system by the command
sudo mkdir -p /data/db/
and
sudo chown id -u /data/db
then I run the mongo again and it worked.
I face same issue after searching a lot I solve this by following :
sudo service mongodb stop
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair --dbpath /var/lib/mongodb
sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb
sudo service mongodb start
If all the above solution does not work: go to service (start>search>services) and start mongodb service. Then, in a cmd prompt, after going to bin, type :/>mongo
To connect with mongo we have to first start 'mongod' services.
following output you can see :
$ mongod
2017-03-05T00:31:39.055+0530 I CONTROL [initandlisten] MongoDB starting : pid=1481 port=27017 dbpath=/data/db 64-bit host=Prabhu-Nandans-Mac.local
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] db version v3.4.2
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] allocator: system
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] modules: none
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] build environment:
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] distarch: x86_64
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] target_arch: x86_64
2017-03-05T00:31:39.056+0530 I CONTROL [initandlisten] options: {}
2017-03-05T00:31:39.056+0530 W - [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2017-03-05T00:31:39.057+0530 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-03-05T00:31:39.057+0530 W STORAGE [initandlisten] Recovering data from the last clean checkpoint.
2017-03-05T00:31:39.057+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten]
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten]
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten]
2017-03-05T00:31:39.620+0530 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-03-05T00:31:39.643+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-03-05T00:31:39.643+0530 I NETWORK [thread1] waiting for connections on port 27017
2017-03-05T00:31:40.008+0530 I FTDC [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
2017-03-05T00:32:03.832+0530 I NETWORK [thread1] connection accepted from 127.0.0.1:49806 #1 (1 connection now open)
2017-03-05T00:32:03.833+0530 I NETWORK [conn1] received client metadata from 127.0.0.1:49806 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.4.2" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "16.4.0" } }
2017-03-05T00:32:08.376+0530 I - [conn1] end connection 127.0.0.1:49806 (1 connection now open)
After that open another terminal and just type 'mongo'.
Following is output you can see :
$ mongo
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2
Your issue solved :)
I also have the same problem then I got fixed by these two lines of code. Hope, it helps
systemctl start mongod
systemctl enable mongod
Start monogdb service using
sudo service mongod start
then from the new window or terminal start mongo client using
mongo
After exhausting lots and lots of sulotions, I did-
sudo brew services start mongodb-community rather than
sudo service mongod start and it worked.
So, first try
sudo brew services start mongodb-community
and then to start the mongo shell, do-
mongo
FOR MACOS
Check the status of the services:
brew services
If you have something like:
Name Status
mongodb-community error
So you can just to stop and restart the service like this:
brew services stop mongodb-community
brew services start mongodb-community
This was happening with me today and I resolved it in following way.
Machine: I'm using Windows 10 machine and downloaded the latest MongoDB - Community edition.
So, the problem was, I did not have C:\data\db created.
Without creating C:\data\db, I opened CMD terminal and started the database using mongod command at terminal
C:\YourInstallationPath\bin>mongod
And when I fired mongo command then I was getting the problem.
Twist, I created the necessary folders but still was getting the problem. And this is because mongo server was already running. To fix it, I fired up mongod command again, and it automatically referenced to C:\data\db.
Other users have suggested to add C:\data\db but did not talk about executing mongod again, which exactly solved my problem.
I had same problem to connect mongodb after install using brew on macOS.
The problem was also mongod.lock but before i had mongodb 3.6 installed and database directory was /usr/local/var/mongodb and it have old files and mongod.lock
Simple i moved my old database files to different folder and removed everything from /usr/local/var/mongodb
Then restarted :
brew services restart mongodb
And it's working fine now.
I was getting this error on ubuntu but you can try with the following command:
sudo service mongod start
You can try with following command:
sudo service mongod start
in my case in windows and ubuntu, i needed to create /data/db folder in root. In ubuntu, i needed one additional option; to give permissions for directory.
windows
mkdir c:/data/db
ubuntu:
sudo mkdir -p /data/db
sudo chmod 700 /data/db
then run
sudo service mongod start
check
sudo service mongod status
and then run
mongo
Remove mongod.lock file. And run "mongod -repair". uninstall/reinstall mongod service fixed that problem for me.
Thanks.
Another solution that resolved this same error for me, though this one might only be if you are accessing mongo (locally) via a SSH connection via a virtual machine (at least that's my setup), and may be a linux specific environment variable issue:
export LC_ALL=C
Also, I have had more success running mongo as a daemon service then with sudo service start, my understanding is this uses command line arguments rather then the config file so it likely is an issue with my config file:
mongod --fork --logpath /var/log/mongodb.log --auth --port 27017 --dbpath /var/lib/mongodb/admin
Create the folder C:data/db if it doesn't already exist on your computer. Turns out MongoDB requires the existence of this folder structure 'data/db' to run. I hope this helps someone.
The cause by me was the space - run this in the console:
df -h
or more specifically:
du -hs /var/lib/mongodb/
to check he disk usage. If it's ~ 99% - just clean up some space and try again!
First, go to c:\mongodb\bin> to turn on mongoDB, if you see in console that mongo is listening in port 27017, it is OK
If not, close console and create folder c:\data\db and start mongod again
if all the solution above doesn't work out perhaps then this might be one to help. Somewhere down the line you may have made connection to your local mongodb database via vagrant boxes.
vagrant up and then ssh into your vagrant machine in which you've made connection with mongodb (vagrant ssh vagrant_box_name)
comment out the bind_ip line from /etc/mongod.conf using # (sudo nano /etc/mongod.conf )
restart your mongodb daemon service (sudo service mongod restart)
voila...
OK, this may be strange. My error happened because my log grew exponentially and clogged up server space hence mongo didn't get enough space to store anything.
so I cleared the log
> /var/log/mongod.log
When we take taskbar manager, go to Service tab. There MongoDB status shows the stopped. Right click for start. Its will connect MongoDB server version.
for checking type "db".
db
test
It will work fine.