Cannot start mongodb server - mongodb

I'm following this tutorial, as well as this one, and I keep getting the same error when starting up my mongodb server.
Running just mongo returns
zsh: command not found: mongod
Running ./mongod returns
zsh: exec format error: ./mongod
Running sudo ./mongod returns
./mongod: ./mongod: cannot execute binary file
My mongodb folder is located in ~/mongodb, which is where the bin folder is. I also created the directory where Mongo will store the data in /data/db, with the correct permissions: drwxr-xr-x. I don't know what I'm missing, or what I'm doing wrong.
How do I start the mongodb server?

Solved
I was using the wrong OS. I downloaded the linux version when I should have downloaded the OS X version since I'm on a Mac. Once I did, everything worked fine.

Much more robust is if you start it as a service with sudo service mongod start
Alternatively, you need to make sure the directory is added to .bashrc.

try this command. It worked for me in git bash
./mongod.exe --port <port number> --dbpath <db folder path>
Ex:
./mongod.exe --port 27017 --dbpath E:/Projects/Databases/data/db

Most likely the path to your MongoDB is not within your $PATH. If you are on linux you can quickly run:
echo $PATH
If it is not in your path, then you want to add it:
export PATH=/path_to_mongodb_bin/:$PATH
Once done, attempt to start mongodb by running:
mongod

Related

getting error while connecting to mongo.exe [duplicate]

I'm trying to run Mongo from the Command-Line:
What's wrong? (I've IIS on localhost:80). And Apache on port 8080. Are there any issues
with this?
C:\MONGO\Project1\mongo\bin>mongo --port 27017
MongoDB shell version: 2.0.3
connecting to: 127.0.0.1:27017/test
Sat Mar 10 16:16:45 Error: couldn't connect to server 127.0.0.1:27017 shell/mong
o.js:86
exception: connect failed
I found that when I got this error it wasn't because I didn't have my default db path set up. It was because I was trying to run mongo.exe before running mongod.exe.
Did you create the default db path?
It defaults to "/data/db directory (or c:\data\db on Windows)"
Source: http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo
As Admin, create directory:
mkdir c:\mongo\data\db
As Admin, install service:
.\mongod.exe --install --logpath c:\mongo\logs --logappend --bind_ip 127.0.0.1 --dbpath c:\mongo\data\db --directoryperdb
Start MongoDB:
net start MongoDB
Start Mongo Shell:
c:\mongo\bin\mongo.exe
Follow
Create default db folder.
c:\data\db
and also log folder
c:\data\log\mongo.log
or use following commands in command-prompt
mkdir c:\data\log
mkdir c:\data\db
Create config file in bin folder of mongo (or you may in save your desired destination).
Add following in text file named "mongod" and save it as
mongod.cfg
dbpath=c:\data\db
logpath=c:\data\log\mongo.log
or use following commands in command-prompt
echo dbpath=c:\data\db>> "mongod.cfg"
echo logpath=c:\data\log\mongo.log>> "mongod.cfg"
Now open command-prompt (administrator) and run the following command to start mongo server
mongod
Open another command-prompt (don't close 1st prompt) and run client command:
mongo
Hope this will help or you have done this already.
The error occurs when trying to run mongo.exe WITHOUT having executed mongod.exe.
The following batch script solved the problem:
#echo off
cd C:\mongodb\bin\
start mongod.exe
start mongo.exe
exit
If you are getting these type of errors when running mongod from command line or running mongodb server,
then follow these steps,
Create db and log directories in C: drive
C:/data/db and C:data/log
Create an empty log file in log dir named mongo.log
Run mongod from command line to run the mongodb server or create a batch file on desktop which can run the mongod.exe file from your mongodb installation direction. That way you just have to click the batch file from your desktop and mongodb will start.
If you have 32-bit system, try using --journal with mongod command.
Create default db folder.
c:\data\db
and also log folder
c:\data\log\mongo.log
or use following commands in command-prompt
mkdir c:\data\log
mkdir c:\data\db
you can use below command,
mongod --dbpath=D:\home\mongodata
where D:\home\mongodata is the data storage path
Go to C:\Program Files\MongoDB\Server\3.4\bin using cmd and
write mongod.
Open another cmd by right click and run as admin point to your
monogodb installed directory as mentioned above and then just like
write this mongo.exe
After that, write db.test.save({Field:'Hello mongodb'}) this command
will insert a field having name Field and value is Hello
mongodb.
After, check the record db.test.find() and press enter you will find
the record that you have recently entered.
Steps to start a certain local MongoDB instance and to connect to in from NodeJS app:
Create mongod.cfg for a new database using the path C:\Program Files\MongoDB\Server\4.0\mongod.cfg with the content
systemLog:
destination: file
path: C:\Program Files\MongoDB\Server\4.0\log\mongod.log
storage:
dbPath: C:\Program Files\MongoDB\Server\4.0\data\db
Install mongoDB database by running
mongod.exe --config "C:\Program Files\MongoDB\Server\4.0\mongod.cfg" --install
Run a particular mongoDB database
mongod.exe --config "C:\Program Files\MongoDB\Server\4.0\mongod.cfg"
Run mongoDB service
mongo 127.0.0.1:27017/db
and !see mongoDB actual connection string to coonect to the service from NodeJS app
MongoDB shell version v4.0.9
connecting to: mongodb://127.0.0.1:27017/db?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c7ed5ab4-c64e-4bb8-aad0-ab4736406c03") }
MongoDB server version: 4.0.9
Server has startup warnings:
...
For this error, if you are using windows 7 or windows server 2008 R2, the problem could be that you have to install a microsoft hotfix.
Refer to this link: https://support.microsoft.com/en-us/kb/2731284

How to resolve MongoDB failing to instantiate [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I followed the MongoDb Docs to setup my first MongoDb,
When I start MongoDB using the command
C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe
I get the following error
exception in initAndListen: 29 Data directory C:\data\db\ not found., terminating
shutdown: going to close listening sockets...
shutdown: going to flush diaglog...
now exiting
shutting down with code:100
MongoDB needs a folder to store the database. Create a C:\data\db\ directory:
mkdir C:\data\db
and then start MongoDB:
C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe
Sometimes C:\data\db folder already exists due to previous installation. So if for this reason mongod.exe does not work, you may delete all the contents from C:\data\db folder and execute mongod.exeagain.
For macOS users to fix this issue:
You need to go through the following steps:
Create the “db” directory. This is where the Mongo data files will live. You can create the directory in the default location by running:
sudo mkdir -p /data/db
Make sure that the /data/db directory has the right permissions by running:
sudo chown -R `id -un` /data/db
You're all set now and you can run sudo mongod to start the Mongo server.
It's not working if you run only mongod
Source.
Same issue on my Mac (using Brew) solved using:
sudo mongod
For macOS users take care of below issue:
if you installing MongoDB Community on macOS using .tgz Tarball
((Starting with macOS 10.15 Catalina, Apple restricts access to the MongoDB default data directory of /data/db. On macOS 10.15 Catalina, you must use a different data directory, such as /usr/local/var/mongodb.))
you can solve it as the following:
(MacOS Catalina onwards)
Apple created a new Volume in Catalina for security purposes. If you’re on Catalina, you need to create the /data/db folder in System/Volumes/Data.
Use this command:
sudo mkdir -p /System/Volumes/Data/data/db
Then, use this command to give permissions:
sudo chown -R `id -un` /System/Volumes/Data/data/db
this will replace normal
sudo mkdir -p /data/db
Make sure that the /data/db directory has the right permissions by running:
sudo chown -R `id -un` /data/db
once you finish and start mongoDB you can use the following in terminal:
sudo mongod --dbpath /System/Volumes/Data/data/db
To change default db folder C:\data\db in windows, the command is:
--dbpath
For example:
\mongod --dbpath C:\myfolder
Mac Users
Instead of running MongoDB with:
sudo mongod
You can use mongod instead if you:
Locate the data folder of mongodb (usually ~/data)
Add permission to read + write with sudo chmod -R ugo+rw data
If you need to use sudo when running mongodb (sudo mongod), that means you don't have read and write permission on the mongodb data folder
Please take following steps:
As other friends mentioned, you should make a directory first for your database data to be stored. This folder could be something like:
C:\mongo-data
From command line navigate to where you have installed mongodb and where mongod.exe resides. In my case the full path is:
C:\Program Files\MongoDB\Server\3.4\bin
From here run mongod.exe and pass it the path to the folder you created in step one using the flag --dbpath as follows:
mongod.exe --dbpath "C:\mongo-data"
Please Note: If you are on windows it is necessary to use double-quotes ("") in the above to run properly.
In this way you will get something like the following:
2017-06-14T12:45:59.892+0430 I NETWORK [thread1] waiting for connections on port 27017
If you use single quotes (' ') on windows, you will get:
2017-06-14T01:13:45.965-0700 I CONTROL [initandlisten] shutting down with code:100
Hope it helps to resolve the issue.
To run Mongo DB demon with mongod command, you should have a database directory, probably you need to run:
mkdir C:\data\db
Also, MongoDB need to have a write permissions for that directory or it should be run with superuser permissions, like sudo mongod.
I kept getting the following error when I tried to start mongodb (on mac os).
"shutting down with code:100"
I was using the following command:
./mongod --dbpath=~/mongo-data
The fix for me was that I didn't need the "=" sign and this was causing the error. So I did
./mongod --dbpath ~/mongo-data
Just wanted to throw this out there because the error in no way specifies that this is the problem. I almost removed the contents of the ~/mongo-data directory to see if that helped. Glad I remembered that cli args sometimes do not use the "=" sign.
first you have to create data directory where MongoDB stores data. MongoDB’s default data directory path is the absolute path \data\db on the drive from which you start MongoDB.
if you have install in C:/ drive then you have to create data\db directory. for doing this
run command in cmd
C:\>mkdir data\db
To start MongoDB, run mongod.exe.
"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --dbpath="c:\data\db"
The --dbpath option points to your database directory.
Connect to MongoDB.
"C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe"
to check all work good :
show dbs
1.If it shows error (shutting down
with code 100) that means it is not finding the desired
location of file.
1.a If its before macOS Catalina then create directory with
sudo mkdir -p /data/db and give permissions to use it
sudo chown -R id -un /data/db.
1.b if it macOS Catalina onwards then make
sudo mkdir -p /System/Volumes/data/db and give it
permissions
sudo chown -R id -un /System/Volumes/data/db.
2.Starting mongo db brew services run mongodb-community
3.Type mongod or mongod --dbpath /System/Volumes/Data/data/db
4.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
4.a Either you change the port of mongod by specifying port
number
mongod --dbpath /System/Volumes/Data/data/db —port 27018.
4.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
5.Repeat the step 2 and 3.
In MacOS:-
If you forgot to give the path of the previously created database while running the mongo server, the above error will appear.
sudo ./mongod --dbpath ../../mongo-data/
Reference
Note :- ./mongod && ../../mongo-data is relative path.
So you can avoid it by configuration in environment variable
Reference
For windows i've got same issue.
The fix was - i need to run command line as administrator.
if you already have the directory, check the dir permissions or try to restart mongo with sudo.
sudo brew services start mongodb
In my case, I got a similar error and it was happening because I had run mongod with the root user and that had created a log file only accessible by the root. I could fix this by changing the ownership from root to the user you normally run mongod from. The log file was in /var/lib/mongodb/journal/
I you are using Virtualbox check your VM.
docker-machine ssh
df -h
Look at dev/sda1 if you do not have any free space this may be due to a large number of images, or containers. you can remove them using "docker rm" and "docker rmi"
This exit code will also be given if you are changing MongoDB versions and the data directory is incompatible, such as with a downgrade. Move the old directory elsewhere, and create a new directory (as per the instructions given in other answers).
Aravind.
It happened with me too because I stopped the MongoDB by the Task Manager.
Creating the C:\data\db folder and starting the MongoDB at C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe worked for me, as cespon suggested, but the MongoDB didn't show any of my Databases previously created.
Then, removing the C:\data\db folder and repairing the installation with the MongoDB installer, I recovered my data and started normally the MongoDB.
(I'm very new with MongoDB, but it helped me solve this problem and recover may previews data).
typed mongod and getting error
Errors:
exception in initAndListen: NonExistentPath: Data directory /data/db not found.,
terminating
shuts down with Code 100
Then try with (create data and db folder with all permission)
mongod --dbpath=/data
use new tab and type mongo.
>use dbs
If still you are facing prob
then you can check for mac catalina: (https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x-tarball/)
for windows: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows-unattended/

getting an error when firing up mongodb in terminal [duplicate]

I'm getting the following error when I try to run "mongod" in the terminal. I've tried uninstalling, reinstalling, and restarting the machine. Any suggestions on how to get it working would be amazing.
ERROR:
dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
Side note:
Node also stopped working on my machine around the same time that I got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
Any help would be much appreciated!
This should work to ensure that the directory is set up in the right place so that Mongo can find it:
sudo mkdir -p /data/db/
sudo chown `id -u` /data/db
You need to create the directory on root /data/db or set any other path with the following command :
mongod --dbpath /srv/mongodb/
See the example link
I solved the problem with :
sudo mongod --dbpath=/var/lib/mongodb and then mongo to access the mongodb Shell.
Change the user of the new data directory:
chown mongodb [rute_directory]
And try another time to start the mongo service
service mongod start
I solve the same problem with this.
Daemons (usually ending with d) are normally started as services. Starting the service (daemon) will allow mongodb to work as designed (without permission changes if integrates well with your distro). I start it using the service named mongodb instead of starting mongod directly--on distro with systemd enable on startup then run like:
sudo systemctl enable mongodb
sudo systemctl start mongodb
or, on distro with upstart (if you have /etc/init) or init (if you have /etc/init.d) ( https://www.tecmint.com/systemd-replaces-init-in-linux/ ) instead run:
sudo service mongodb enable
sudo service mongodb start
If you have a distro with rc ("run commands") such as Gentoo (settings in /etc/init.d) (https://forums.gentoo.org/viewtopic-t-854138-start-0.html) run:
rc-update add mongodb default
/etc/init.d/mongodb start
In a distro/version of FreeBSD which still has rc (check whether your version switched to systemd, otherwise see below):
add the following line to /etc/rc.conf:
mongod_enable="YES"
then:
sudo service mongod start
After starting the service, an unpriveleged user can use mongo, and each user will have separate data.
I also got the error that "The file /data/db doesn't exist" when I tried to save my file using the "mkdir -p /data/db" command(using both with and without sudo command). But later on one site, a person named Emil answered that the path "/data/db" no longer works on Mac, so use "~/data/db" instead
i.e., use the command
mkdir -p ~/data/db
instead of previous command.
Moreover, use
mongod --dbpath ~/data/db
to run mongod
It worked for me, hope it work for others too facing the same problem

Mongo is letting me down

I've been trying to run mongo on my system, but I just doesn't want to start. I've installed mongodb with brew. Both mongo and mongod are on my system and I can use them. But the mongod process won't start.
These are the steps I'm taking after I installed mongo on my system with brew.
$ mongod
all output going to: /usr/local/var/log/mongodb/mongo.log
$
It seems mongod is closing directly, because I don't see any process running and it gives me the dollar sign back again. Thereby there's no rotating icon in my terminal, so it isn't running.
If I open a new window in the terminal after running the above command, I'm getting this error:
$ mongo
MongoDB shell version: 2.4.3
connecting to: test
Thu May 23 12:22:09.314 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
exception: connect failed
$
This output is a logical error seen from the fact mongod didn't do a thing. But when I run this:
$ ps -ef | grep mongod
501 99123 15827 0 12:24PM ttys001 0:00.00 grep mongod
$
So I'm not sure or it's running or not.. You guys know a solution for this? Because I can't figure out what I'm doing wrong..
update
I've tried to change the db path and that works partially. I'm now able to run mongod command, but I need to specify the dbPath even though I have the dbPath changed in the config file.
$ mongod --dbpath ~/data/db/
And when I try to run mongod by itself, it won't run..
$ mongod
all output going to: /usr/local/var/log/mongodb/mongo.log
$
I don't have a working solution, but from your output, it seems like mongod is running daemonized. You could try setting the 'fork' option to false (or uncommenting it) in /usr/local/Cellar/mongodb/2.4.x-x86_64/mongod.conf and running mongod with the -v / --verbose flag to see if that gives you more details.
Also, are you sure you're actually using the homebrew version of mongo and not some previously installed version? You can check which mongod is used by running:
➜ ~ which mongod
/usr/local/bin/mongod
And the following to see if that's indeed the version that got installed using homebrew:
➜ ~ ls -l /usr/local/bin/mongod
lrwxr-xr-x 1 user admin 41 21 mrt 22:06 /usr/local/bin/mongod -> ../Cellar/mongodb/2.4.x-x86_64/bin/mongod
The default data directory is /data/db. In order to have that work by default you need to do two things:
sudo mkdir -p /data/db
sudo chown `whoami` /data/db

MongoDB on Ubuntu won't start as a service, nothing in the log

Am running MongoDB 2.2 on Ubuntu and if I run:
sudo mongod
I get an error that it can't find /data/db, which is not where the database is. In mongod.conf the database path is specified as the Ubuntu 10gen default /var/lib/mongodb which is where the db is located. Seems like mongod is not finding the conf file. So when I run:
sudo mongod -f /etc/mongodb.conf
The server starts up fine and output is logged to the log file: /var/log/mongodb/mongodb.log. All is happy. I can switch to another shell, log into mongo shell, see the databases and run queries.
So, I cancel out of that and try to run as a service:
> sudo status mongodb
mongodb stop/waiting
> sudo start mongodb
mongodb start/running, process 10468
Looks good so far, but the mongo server did not start. Running another:
> sudo status mongodb
mongodb stop/waiting
> mongo
MongoDB shell version: 2.2.0
connecting to: test
Sat Sep 1 19:07:43 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
"test" is not the correct database, and nothing appears in the log file.
I am at a loss as to what could be wrong. I checked the upstart scripts and they seem fine. /etc/init/mongodb.conf runs:
mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf
OK, this all comes down to permissions, but let's take it step by step. When you run sudo mongod it does not load a config file at all, it literally starts with the compiled in defaults - port 27017, database path of /data/db etc. - that is why you got the error about not being able to find that folder. The "Ubuntu default" is only used when you point it at the config file (if you start using the service command, this is done for you behind the scenes).
Next you ran it like this:
sudo mongod -f /etc/mongodb.conf
If there weren't problems before, then there will be now - you have run the process, with your normal config (pointing at your usual dbpath and log) as the root user. That means that there are going to now be a number of files in that normal MongoDB folder with the user:group of root:root.
This will cause errors when you try to start it as a normal service again, because the mongodb user (which the service will attempt to run as) will not have permission to access those root:root files, and most notably, it will probably not be able to write to the log file to give you any information.
Therefore, to run it as a normal service, we need to fix those permissions. First, make sure MongoDB is not currently running as root, then:
cd /var/log/mongodb
sudo chown -R mongodb:mongodb .
cd /var/lib/mongodb
sudo chown -R mongodb:mongodb .
That should fix it up (assuming the user:group is mongodb:mongodb), though it's probably best to verify with an ls -al or similar to be sure. Once this is done you should be able to get the service to start successfully again.
First confirm that the mongodb user/group has permission to write to both the data directory and log file:
$ sudo chown -R mongodb:mongodb /var/lib/mongodb/.
$ sudo chown -R mongodb:mongodb /var/log/mongodb.log
Start up MongoDB as a Daemon (background process) using the following command:
$ mongod --fork --dbpath /var/lib/mongodb/ --smallfiles --logpath
/var/log/mongodb.log --logappend
To Shut Down MongoDB enter the Mongo CLI, access the admin and issue the shutdown command:
$ ./mongo
> use admin
> db.shutdownServer()
Ref: http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo
I too had the same problem. So I went to cd /var/lib/mongodb/ and deleted the mongod.lock file
Then it worked for me.
After checking all permission in the data, journal and log folders as suggested by #nelsonic, my problem was solved by giving permission to lock file in the /tmp folder
sudo chown mongod:mongod mongodb-27017.sock
I was running it as a AWS Amazon Linux instance.
I figured that out by executing as the mongod user as below, and then, researching the error code. It might be useful for other troubleshooting.
sudo -S -u mongod mongod -f /etc/mongod.conf
Just try this command:
sudo chown mongodb /tmp/mongodb-27017.sock
Nothing worked for me, then I've found that it was a permissions problem on /tmp directory:
sudo chmod 1777 /tmp
sudo chown root:root /tmp
None of the above answers worked for me. I finally figured it out by debugging the init script with:
sudo bash -x /etc/init.d/mongodb start
And seeing it was passing the wrong config path to mongod. I simply changed the line in /etc/init.d/mongodb from "CONF=/etc/mongodb.conf" to "CONF=/etc/mongod.conf". Version 2 uses the former, and installing version 3 added /etc/mongod.conf with the new format but apparently did not update the init script.
UPDATE: I now have a much stranger problem where the init script works, but only if I run it with "sudo bash -x /etc/init.d/mongodb start" and not with "sudo service mongodb start". Same thing for stop.
My mongodb was starting when launched from the command line as the mongod user, but not as a service with User=mongod.
After an hour checking permissions, definition of the service, sockets... it was SElinux !
In /etc/selinux/config I switched from enforcing to permissive and reboot. It is now ok.
After none of the above answers worked for me, deleting my log file brought Mongo back to life.
These days this error can occur if you've updated mongod and you are running and old database. Mongod will be using the wiredTiger engine by default and you'll have a mmapv1 database
edit the engine setting in /etc/mongod.conf
# engine: wiredTiger
engine: mmapv1
Careful - YAML is whitespace sensitive
journalctl/systemd won't see this problem. Check the mongod log in /var/log/mongodb/mongod.log
I presume you can convert the database with something like the steps outlined here
https://docs.mongodb.com/manual/tutorial/change-standalone-wiredtiger/