Monday, February 24, 2014

MongoDB Installation on Linux

To install it on CentOS, run the following commands as root or using sudo.
vi /etc/yum.repos.d/mongodb.repo
Add:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
Run:
yum install mongo-10gen mongo-10gen-server
Start mongod as a service:
service mongod start
Stop mongod service:
service mongod stop
View MongoDB log file:
tail -f /var/log/mongo/mongod.log
View MongoDB configuration:
more /etc/mongod.conf
View mongod script:
more /etc/rc.d/init.d/mongod
To access MongoDB admin console:
http://[mongodb-host]:28017
To access MongoDB from the command line, login to the server running it:
mongo
show dbs (list of existing databases)
use [db-name] (ex: use nbdb; if it doesn't exist, create it)
show collections (list of document collections)
db.[collection-name].find() (list the contents of a collection)
exit
On MacOS:

brew update
brew install mongodb
sudo mkdir -p /data/db
sudo mongod

1 comment:

  1. For Ubuntu:

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
    echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
    sudo apt-get update
    sudo apt-get install mongodb-org
    sudo /etc/init.d/mongod start
    ps -aef|grep mongo
    sudo /etc/init.d/mongod stop
    ps -aef|grep mongo
    sudo /etc/init.d/mongod start
    tail -f /var/log/mongodb/mongod.log

    ReplyDelete