set up mongo db in windows and osx

OSX

1. download mongo and unzip to some folder, rename folder to mongodb. i put it under ~/Documents/develop/mongodb

2. create  folder “data” under “mongodb”.  create folder “db” under “data”

create folder “logs” under “mongodb”. create file “mongodb.log”

3. create file mongodb.conf under ~/Documents/develop/mongodb/bin with content:

dbpath = ~/Documents/develop/mongodb/data/db
directoryperdb = true
logpath = ~/Documents/develop/mongodb/logs/mongodb.log
logappend = true
rest = true

now you can run mongo db server under bin folder: “mongod -f mongodb.conf”

and start mongo by run “mongo” under bin folder.

to make it easier to start.

1. add a file “.profile” under ~/ with content:

# MongoDB server Alias
alias mongod=”`/Documents/develop/mongodb/bin/mongod –config=~/Documents/develop/mongodb/bin/mongod.conf”

#MongoDB instance Alias
alias mongo=”~/Documents/develop/mongodb/bin/mongo”

restart the shell, you should be able to run mongod and mongo directly .

Note: if you also have .bash_profile, then write the above content there since it has higher priority. More info HERE

Windows

step 1-3 is similar.

To make mongod a windows service, we can run:

C:\mongodb\bin\mongod.exe --config C:\mongodb\mongod.cfg --install

To run the MongoDB service:

net start MongoDB

Stop or Remove the MongoDB Service

To stop the MongoDB service:

net stop MongoDB

To remove the MongoDB service:

C:\mongodb\bin\mongod.exe --remove
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s