Farid
Farid

Reputation: 1665

Cannot start mongodb server

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?

Upvotes: 1

Views: 4327

Answers (4)

CyrilDex
CyrilDex

Reputation: 177

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

Upvotes: 1

Lasal Sethiya
Lasal Sethiya

Reputation: 201

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

Upvotes: 1

Farid
Farid

Reputation: 1665

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.

Upvotes: 2

Nickpick
Nickpick

Reputation: 6597

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.

Upvotes: 1

Related Questions