Reputation: 29064
I am trying to install mongodb on my system and following these steps(http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/) in doing so. I have installed Homebrew and MacPorts and have installed the mongodb using both Homebrew and MacPorts. But when i type mongod:
I get this:
mongod --help for help and startup options
Sun Sep 9 20:58:35 [initandlisten] MongoDB starting : pid=6381 port=27017 dbpath=/data/db/ 64-bit host=Cs-MacBook-Pro.local
Sun Sep 9 20:58:35 [initandlisten] db version v2.0.7, pdfile version 4.5
Sun Sep 9 20:58:35 [initandlisten] git version: nogitversion
Sun Sep 9 20:58:35 [initandlisten] build info: Darwin Cs-MacBook-Pro.local 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr 9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Sun Sep 9 20:58:35 [initandlisten] options: {}
Sun Sep 9 20:58:35 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating
Sun Sep 9 20:58:35 dbexit:
Sun Sep 9 20:58:35 [initandlisten] shutdown: going to close listening sockets...
Sun Sep 9 20:58:35 [initandlisten] shutdown: going to flush diaglog...
Sun Sep 9 20:58:35 [initandlisten] shutdown: going to close sockets...
Sun Sep 9 20:58:35 [initandlisten] shutdown: waiting for fs preallocator...
Sun Sep 9 20:58:35 [initandlisten] shutdown: lock for final commit...
Sun Sep 9 20:58:35 [initandlisten] shutdown: final commit...
Sun Sep 9 20:58:35 [initandlisten] shutdown: closing all files...
Sun Sep 9 20:58:35 [initandlisten] closeAllFiles() finished
Sun Sep 9 20:58:35 dbexit: really exiting now
When i type mongo, i get this:
MongoDB shell version: 2.0.7
connecting to: test
Sun Sep 9 20:58:39 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
Need some help on this...
Upvotes: 2
Views: 12424
Reputation: 31
I spent quite a while trying to figure out how to install MongoDB and Mongoose. My problem with the new macOS Catalina update, the folder /data/db
is read-only, you cannot modify it, so you have to store your database files somewhere else. I had to go through the MongoDB Installation Documentation, which is summarized below.
1. To install xcode, run in your macOS Terminal:
$ xcode-select --install
2. To install brew
use the official Homebrew Installation Instructions.
3. To tap the MongoDB Homebrew Tap, run in your macOS Terminal:
$ brew tap mongodb/brew
4. To update Homebrew and all existing formulae:
$ brew update
5. To install MongoDB:
$ brew install [email protected]
To start MongoDB, run:
$ brew services start [email protected]
To stop MongoDB, run:
$ brew services stop [email protected]
To verify that MongoDB is running:
$ brew services list
See How to Start MongoDB on Mac for more help.
To check where your database files are being stored run:
$ sudo lsof -p `ps aux | grep mongodb | head -n1 | tr -s ' ' | cut -d' ' -f 2` | grep REG
When I ran this command it showed that my files are being stored in a hidden file in my harddrive, Macintosh HD. In Finder you can push SHFT + CMD + .
to show hidden files. If this command returns file names with a folder called mongodb, then you are good to go.
If your files are still read-only, you can try to overwrite the default storage path with:
$ mongod --dbpath /System/Volumes/Data/data/db
To verify your MongoDB version:
$ mongod --version
Upvotes: 2
Reputation: 903
You can easily install mongoDB on your local machine using the following steps:
sudo nano /etc/paths
the contents of your paths should appear go to the folder containing your MongoDB folder and right click on this MongoDB folder and click on copy to copy the path to this folder then go to the terminal and paste the copied path in the paths file and add at the end of it /bin because bin will contain all MongoDB shell commands you will be using then press control + x then y(this means you are telling the terminal save my file) to save the changes then enter to quit nano.
Upvotes: 0
Reputation: 428
Here is step which help you to install mongodb on your mac.
1.Download mongodb-osx-x86_64-3.2.6.tgz from server.
https://www.mongodb.org/downloads#production
2.Open terminal.
3.Extract that folder
$ tar xvf mongodb-osx-x86_64-3.2.6.tgz
4.Go to that folder
$ cd mongodb-osx-x86_64-3.2.6
5.$ cd bin
Now goes to root level & enter password
$ sudo bash
Then create data folder
root
drwxrwxrwx 2 root wheel 68 Apr 28 15:04 /data/db
So now you are in bin folder again, So execute this command
$ ./mongod
So, It will waiting for connection.
$ cd mongodb-osx-x86_64-3.2.6
$ cd bin
$ ./mongo
db.names.insert({'name':'piyush'})
Also, Retrive it by
db.names.find()
https://piyushkachariya111.wordpress.com/2016/04/28/installing-mongodb-on-a-mac/
Upvotes: 1
Reputation: 2271
Here is the Manual Method to install MongoDB in MAC
1.Download mongodb "mongodb-osx-ssl-x86_64-3.6.5.tgz" file
2.Extract it using the command
$ tar -zxvf mongodb-osx-ssl-x86_64-3.6.5.tgz
3.Create a directory and copy the extracted contents to that
$ mkdir mongodb
$ cp -R -n mongodb-osx-ssl-x86_64-3.6.5.tgz/ mongodb
4.Create a file in home directory named .bash_profile and add the bin path to the same as shown below
export PATH=<mongodb-install-directory>/bin:$PATH
5.Create directory data/db in any root location and add permission to the loggedin user using chown
$ sudo mkdir -p /data/db
$ whoami
LoggedInUser
$ sudo chown LoggedInUser /data/db
If we are using different dbpath instead of /data/db (Developer need to add this each time while execution if we are using different location)
mongod --dbpath <path to data directory>
6.Close and open terminal and verify the working using mongod
$ mongod
7.Connect to mongo using mongo command
$ mongo
Upvotes: 0
Reputation: 11
Alternative method:
If you don’t like the default /data/db folder, just specify an alternate path with --dbpath
$ mongod --dbpath /any-directory
Upvotes: 1
Reputation: 2279
Even I faced the same issue while running the mongodb server.
Process 1: Run the activity monitor
and find for the mongodb instance and kill the process and run the command again.
or
Process 2 : Find the \data\db\ data-directory\mongod.lock
file, and delete it and run the command
mongod --repair
After that you`ll see the information log with the following message
shutdown: removing fs lock...
Now run the mongodb
command.
Hope this will helpful.
Upvotes: 0
Reputation: 15379
The other answers did not have the data directory for me (Mac OS Mavericks, Mongo (2.4.x)
The mongo data directory in Mac OS is located
/usr/local/var/mongodb
Upvotes: 4
Reputation: 4175
The answers above are surely good enough but I would also like to give a tip here.
What I would do is:
Download the respective binaries from mongodb site's download section.
Unarchive it in some folder, like /opt/mongo
Then add the path to the $PATH variable by adding the below line in .bashrc file PATH="$PATH:/opt/mongo/bin"
Now you can fire up mongod or mongo or mongoexport etc. from command line just like any other command.
Upvotes: 2
Reputation: 96
I hate to add another answer because the current answer works, but I can't comment that answer so..
You can create the required data directory and give it the same permissions as the user you are logged into OS X as using the following:
sudo mkdir -p /data/db
sudo chown `id -u` /data/db
Then you can fire up mongod using
./path/to/mongod
Upvotes: 8
Reputation:
Create a folder /data/db/
in /
. This is where MongoDB stores all its data. Then make sure it’s readable and writable by MongoDB using chown
or ⌘I in the Finder.
Upvotes: 17