Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

MongoDB Quickstart

Marc Dutoo edited this page Nov 6, 2013 · 12 revisions

Installation process :

On Ubuntu, as said at http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ :

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

On Debian, as said at http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/ :

echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

Then for all do :

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
sudo apt-get update
sudo apt-get install mongodb-10gen

NB. which version : MongoDB is provided as (.deb) packages within distributions (Ubuntu...), however MongoDB provider 10gen provides more up to date packages, which are therefore chosen. (from http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ )

NB. in production, MongoDB 64 bits is required, which will be automatically chosen if you've got a 64 bit system. To make sure : uname -m

NB. to check your system : lsb_release -a

start :

sudo service mongodb start

This should display the following start trace :

Mon Aug 26 19:27:50.152 [initandlisten] db version v2.4.6
Mon Aug 26 19:27:50.152 [initandlisten] git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
Mon Aug 26 19:27:50.152 [initandlisten] build info: Linux bs-linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686     BOOST_LIB_VERSION=1_49
Mon Aug 26 19:27:50.152 [initandlisten] allocator: system
Mon Aug 26 19:27:50.152 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }

To automate startup (required ?) :

update-rc.d mongodb defaults

test :

mongo
db.test.save( { a: 1 } )
db.test.find()

configuration :

Edit /etc/mongodb.conf

FAQ - recover from crash :

problem : no mongo process, even when trying to start it

in log /var/log/mongodb/mongodb.log :

**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
Tue Sep  3 13:59:24.291 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
...

As said at http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/ , solution is :

  • (for production deployments) part of a replica set (OR journaling ??) : restore from a backup or restart the mongod instance with an empty dbpath (that will be sync'd)
  • (for usual development deployments) not running as part of a replica set AND do not have journaling enabled : --repair optionally with --repairpath to write repaired files to

So to repair your development MongoDB, just do this :

su
rm /var/lib/mongodb/mongod.lock
# direct repair
mongod -dbpath /var/lib/mongodb --repair
# ALT in production, to repair to : mongod -dbpath /var/lib/mongodb --repair --repairpath=REPAIRPATH
# and test : mongod -dbpath REPAIRPATH
# change rights (or give user mongodb a HOME a do it as him)
chown -R mongodb /var/lib/mongodb/
chgrp -R mongodb /var/lib/mongodb/
service mongodb start