upgrade mongodb

Liatz picture Liatz · Mar 18, 2012 · Viewed 31.9k times · Source

I'm looking for the easiest and the most recommended way to upgrade mongodb version (standalone server and mongodb shell).

Are there any terminal (for mac) commands that i can follow in order to upgrade?

I tried to stop the server by $ mongo

use admin db.shutdownServer()
i get : Sat Mar 17 20:38:15 DBClientCursor::init call() failed Sat Mar 17 20:38:15 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1:27017 server should be down... Sat Mar 17 20:38:15 trying reconnect to 127.0.0.1:27017 Sat Mar 17 20:38:15 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017

I understand that after stopping the server i need to change the bin folder of mongodb. (which i'm failing to do because mongo is in use)

If someone knows an easier way to only upgrade the mongodb version i would really thank him/her! thank you.

Answer

nelsonic picture nelsonic · Oct 26, 2012

To Upgrade MongoDB on Ubuntu

First, Backup your data using Mongoexport

e.g:

mongoexport --db sales --collection contacts --out contacts.json --journal

Then check which version of MongoDB you are running by issuing the command:

$ mongod --version

db version v1.8.2, pdfile version 4.5 - Wed Oct 24 15:43:13 git version: nogitversion

Confirm if mongo is currently running:

$ ps -deaf | grep mongod

mongodb 15408 1 0 Jun06 ? 13:50:00 /usr/bin/mongod --config /etc/mongodb.conf

To Shutdown MongoDB

$ ./mongo

> use admin

> db.shutdownServer()

server should be down...

Then upgraded following these instructions: How to Install MongoDB on Ubuntu

Add the 10 Gen (creators of MongoDB) public key to apt-get so you trust their package:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

$ echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" >> /etc/apt/sources.list.d/10gen.list

Update your packages:

$ sudo apt-get update

install 10gen's MongoDB Debian/Ubuntu package:

$ sudo apt-get install mongodb-10gen

The following packages will be REMOVED: mongodb

The following NEW packages will be installed: mongodb-10gen

If you get an error, try:

$ apt-get autoremove

Confirm that the mongodb user/group has permission to write to the data directory:

$ sudo chown -R mongodb:mongodb /var/lib/mongodb/.

Start up MongoDB as a Daemon (background process) using the following command:

$ mongod --fork --dbpath /var/lib/mongodb/ --smallfiles --logpath /var/log/mongodb.log --logappend

To Shut Down MongoDB enter the Mongo CLI, access the admin and issue the shutdown command:

$ ./mongo

> use admin

> db.shutdownServer()