upgrade mongodb
Asked Answered
R

6

18

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.

Rivero answered 18/3, 2012 at 11:29 Comment(0)
B
9

shutdown mongodb with:

/usr/bin/mongodb --config $PATH-TO-CONFIG --shutdown

(replace /usr/bin with the right directory) copy new mongodb and restart mongodb afterwards.

Bulbil answered 18/3, 2012 at 11:49 Comment(0)
N
49

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()

Numismatics answered 25/10, 2012 at 22:26 Comment(5)
Perfect instructions! Thank you. The only problem I had was starting the daemon... I had to use sudo otherwise it complained about not being able to write to the log path.Labyrinthodont
Really useful! I had to do a couple of extra things, though: I got bash: /etc/apt/sources.list.d/10gen.list: Permission denied when running echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" >> /etc/apt/sources.list.d/10gen.list. I tried various things, but in the end just echoed to terminal and copied-and-pasted into the file. Also, the install failed for me and said trying to overwrite '/usr/bin/mongo', which is also in package mongodb-clients 1:2.0.4-1ubuntu2.1, so I had to sudo apt-get purge mongodb-clients first.Cockoftherock
It's better to use "|" in the echo instead of the ">>", i.e.: echo 'deb downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.listHusted
**** You should say to backup your data all my data was lost****Thorax
@liadlivnat I've added the Mongoexport link. and CLI line. thanks.Numismatics
B
9

shutdown mongodb with:

/usr/bin/mongodb --config $PATH-TO-CONFIG --shutdown

(replace /usr/bin with the right directory) copy new mongodb and restart mongodb afterwards.

Bulbil answered 18/3, 2012 at 11:49 Comment(0)
H
6

Depends on the version upgrade, but usually if it's a major upgrade (example from 1.8.xx to 2.0.XX) you should do at least the following steps:

  • backup your data (mongoexport or check this MongoDB backup documentation)
  • stop the server (use admin db.shutdownServer() )
  • copy or symbolic link the new mongodb binaries
  • run mongod with the --upgrade flag (mongod - f --upgrade)
  • when upgrade done, restart the mongod server

After that make sure that everything is working properly. If not switch back to the old version, import the data from the backup and check mongoDB jira :)

Heterochromatin answered 18/6, 2012 at 14:25 Comment(0)
R
3

1.Import the public key used by the package management system

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

2. Create a list file for MongoDB.

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

3. Reload local package database. sudo apt-get update

4. stop the existing service sudo service mongodb stop

5. first migrate to 2.4 to 2.6 Install a specific release of MongoDB

sudo apt-get install -y mongodb-org=2.6.12 mongodb-org-server=2.6.12 mongodb-org-shell=2.6.12 mongodb-org-mongos=2.6.12 mongodb-org-tools=2.6.12

6.unlink the temp links remove the lock file. rm /tmp/mongodb-27017.sock

7.restart mongo service sudo service mongodb restart

8. Now finally migrate from 2.6 to 3.0 sudo apt-get install -y mongodb-org=3.0.12 mongodb-org-server=3.0.12 mongodb-org-shell=3.0.12 mongodb-org-mongos=3.0.12 mongodb-org-tools=3.0.12

restart again and voila !!!!

For more details follow the official documentation: mongo doc

Ramrod answered 25/5, 2016 at 11:44 Comment(0)
D
2

To upgrade from version 2 to version 3

I was unsuccessful using the methods in the other answers here, and was finally successful when following the offical document's "Upgrade Binaries" approach, like so:

  1. Stop mongo from running :

    $ sudo service mongod stop

  2. Download the correct binaries

    (from here, and for help getting the correct version see this answer)

  3. Copy the downloaded binaries over :

    $ sudo cp downloaded_binaries/bin/* /usr/bin

  4. Restart mongo :

    $ sudo service mongod start

Dabbs answered 13/1, 2017 at 1:16 Comment(0)
C
0

These are the steps to update MongoDB version 4.2 to 7.0:

Repo File:

[mongodb-org-<version>]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/<version>/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-<version>.asc

Update to 4.4:

  1. Enable the repository for MongoDB-4.4.

  2. Change authorization from enabled to disabled in /etc/mongod.conf.

  3. To ensure 'featureCompatibilityVersion' is set to "4.2":

    db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})
    

    To update 'featureCompatibilityVersion':

    db.adminCommand({setFeatureCompatibilityVersion: "4.2"})
    
  4. To shut down MongoDB: rs.stepDown()

  5. Stop the service: systemctl stop mongod

  6. Update MongoDB: yum update mongodb-org*

  7. Start MongoDB: systemctl start mongod

Update to 5.0:

  1. Enable the repository for MongoDB-5.0.

  2. To ensure 'featureCompatibilityVersion' is set to "4.4":

    db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})
    

    To update 'featureCompatibilityVersion':

    db.adminCommand({setFeatureCompatibilityVersion: "4.4"})
    
  3. To shut down MongoDB: rs.stepDown()

  4. Stop the service: systemctl stop mongod

  5. Update MongoDB: yum update mongodb-org* Ensure the following packages are in the updating list: mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools

  6. Start MongoDB: systemctl start mongod

Update to 6.0:

  1. Enable the repository for MongoDB-6.0.

  2. To ensure 'featureCompatibilityVersion' is set to "5.0":

    db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})
    

    To update 'featureCompatibilityVersion':

    db.adminCommand({setFeatureCompatibilityVersion: "5.0"})
    
  3. To shut down MongoDB: rs.stepDown()

  4. Stop the service: systemctl stop mongod

  5. Update MongoDB: yum update mongodb-org* Ensure the following packages are in the updating list: mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools

  6. Start MongoDB: systemctl start mongod

Update to 7.0:

  1. Enable the repository for MongoDB-7.0.

  2. To ensure 'featureCompatibilityVersion' is set to "6.0":

    db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})
    

    To update 'featureCompatibilityVersion':

    db.adminCommand({setFeatureCompatibilityVersion: "6.0"})
    
  3. To shut down MongoDB: rs.stepDown()

  4. Stop the service: systemctl stop mongod

  5. Update MongoDB: yum update mongodb-org* Ensure the following packages are in the updating list: mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools

  6. Remove/comment the following lines in /etc/mongod.conf:

    #journal:
    #enabled: true
    #pidFilePath: /var/run/mongodb/mongod.pid
    
  7. Remove the sock file: rm /tmp/mongodb-27017.sock

  8. Change the permission of the data directory: chown -R mongod:mongod /data/

  9. Change authorization from disabled to enabled in /etc/mongod.conf

  10. Start MongoDB: systemctl start mongod

Concentration answered 3/5 at 4:9 Comment(1)
OP did not specify the source and destination version of MongoDB. You do not need to repeat the same content for every upgrade between versions. You can simply mention that upgrade must be done step-by-step to next version only (instead of directly skipping multiple versions).Mayhew

© 2022 - 2024 — McMap. All rights reserved.