Install MongoDB
The Easiest Way To Install MongoDB Is To Use A Package Manager or The Pre-Built Binaries:
Package managers
IF you use the homebrew package manager, run:
$ BREW UPDATE
$ BREW Install MongoDB
If you use macports you can install with:
$ Sudo Port Install MongoDB
This Will Take a while to install.
32-bit binaries
NOTE: 64-Bit is Recommended (if You Have A 64-bit System).
$ curl http://downloads.mongodb.org/oSX/mongodb-osx-i386-X.y.z.tgz> Mongo.tgz
$ tar xzf mongo.tgz
Replace x.y.z with the current stable version.
64-bit binaries
$ curl http://downloads.mongodb.org/OSX/mongodb-ox-x86_64-x.y.z.tgz> Mongo.tgz
$ tar xzf mongo.tgz
Replace x.y.z with the current stable version.
Create a Data Directory
By Default MongoDB Will Store Data IN / DATA / DB, But it is’t Automatical Create That Directory. To create it, do:
$ mkdir -p / data / db
You can Also Tell MongoDB to Use A Different Data Directory, with the – dbpath option.
Run and connection to the server
First, Start The MongoDB Server in One Terminal:
$ ./mongodb-xxxxxxx/bin/mongod
In a Separate Terminal, Start The Shell, Which Will Connect To localhost by Default:
$ .mongoDB-xxxxxxx/bin/mongo
> db.foo.save ({a: 1})
> db.foo.find ()
CONGRATULATIONS, You’VE Just Saved and Retrieved Your First Document with MongoDB!