Reputation: 10879
Environment
Linux Mint 17.1
localhost
27017
Background
I installed MongoDB
with:
apt-get install mongodb-10gen=2.4.9
I then 'pinned' the package so that no updates would be applied to it:
echo "mongodb-10gen hold" | sudo dpkg --set-selections
Desired Behaviour
I want to upgrade to the latest version of MongoDB and am looking at the official guide for this process:
http://docs.mongodb.org/manual/release-notes/2.6-upgrade
Early on it states:
To begin the upgrade procedure, connect a 2.6 mongo shell to your MongoDB 2.4 mongos or mongod and run the db.upgradeCheckAllDBs() to check your data set for compatibility.
Question
How do I connect a 2.6 mongo shell
to a 2.4.9 mongod
?
I would guess that I somehow need to just install the 2.6 mongo shell
and run it but:
I've done a mongodump
of all database so have a backup.
Upvotes: 4
Views: 4222
Reputation: 1993
I know you have managed to solve your question, but the following link helped me and I thought I could post it here for future reference and in case somebody else finds it hard upgrading mongodb:
http://blog.lecstor.com/mongodb-upgrade-24-to-26-in-debian
EDIT: A more appropriate answer, quoting the link above:
You have to download the tar version of MongoDB and run the shell straight from there:
$ curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.1.tgz
$ tar -zxvf mongodb-linux-x86_64-2.6.1.tgz
$ ./mongodb-linux-x86_64-2.6.1/bin/mongo
To run the check, you also need to be using the admin database, so..
>use admin
switched to db admin
>db.upgradeCheckAllDBs()
Checking database mydb1
Checking collection mydb1.coll1
Checking collection mydb1.coll2
Checking database mydb2
Checking collection mydb2.coll1
Checking collection mydb2.coll2
Everything is ready for the upgrade!
true
Upvotes: 3
Reputation: 10879
I made an attempt to install mongo
2.6 individually but that caused the other packages to be marked for removal. I ended up just uninstalling the old packages and re-installing the new ones and include the process here for reference.
Some of the steps below didn't work, but i've included them and their results as documentation of what was tried. I had previously done a mongodump
of all databases so had a backup.
The end result is that everything currently seems to be 'working' apart from the admin
database restore.
01. Shut down mongod
mongo
use admin
db.shutdownServer()
from: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
02. Removed the 'pinned package' state of mongodb-10gen
with:
echo "mongodb-10gen install" | sudo dpkg --set-selections
from: https://help.ubuntu.com/community/PinningHowto
03. I then tried to install the latest mongo
with:
sudo apt-get install -y mongodb-org-shell
from: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
04. The shell version seemed to be updated:
mongo --version
MongoDB shell version: 2.6.6
05. But then I couldn't connect with mongo
:
mongo
connecting to: test
2015-01-04T00:08:50.482+1000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-01-04T00:08:50.483+1000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
or mongod
:
mongod
The program 'mongod' is currently not installed. You can install it by typing:
sudo apt-get install mongodb-server
06. I ran the following to see the history of apt-get installs/removals:
less /var/log/apt/history.log
and got:
Start-Date: 2015-01-04 00:02:08
Commandline: apt-get install -y mongodb-org-shell
Install: mongodb-org-shell:amd64 (2.6.6)
Remove: mongodb-10gen:amd64 (2.4.9)
End-Date: 2015-01-04 00:02:21
07. I ran:
dpkg --get-selections
and saw:
mongodb-10gen deinstall
I think 'deinstall' means it is marked for removal.
08. I decided to remove all mongodb-10gen
packages with:
sudo apt-get purge mongodb-10gen
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
gir1.2-clutter-gst-2.0 gir1.2-ges-1.0 gstreamer1.0-gnonlin libav-tools
libavdevice53 libavfilter3 libavresample1 libges-1.0-0 libgoocanvas-common
libgoocanvas3 libmlt++3 libmlt-data libmlt6 libqjson0 libquicktime2
libsoprano4 melt python-dateutil python-gst-1.0 python-matplotlib
python-matplotlib-data python-mlt python-pygoocanvas python-pyparsing
python-tz python3-bs4 python3-markdown shared-desktop-ontologies
soprano-daemon wkhtmltopdf
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
mongodb-10gen*
0 to upgrade, 0 to newly install, 1 to remove and 3 not to upgrade.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Y
(Reading database ... 246460 files and directories currently installed.)
Removing mongodb-10gen (2.4.9) ...
Purging configuration files for mongodb-10gen (2.4.9) ...
dpkg: warning: while removing mongodb-10gen, directory '/var/lib/mongodb' not empty so not removed
from: https://askubuntu.com/a/147177
09. I made a backup of the directory that could not be removed ie /var/lib/mongodb
:
sudo cp -avr /var/lib/mongodb/ /home/
10. And then removed it.
cd /var/lib/
sudo rm -rf mongodb/
11. I searched to see if any mongodb-10gen
packages were remaining:
dpkg --get-selections | grep "mongodb-10gen"
which returned nothing.
12. I installed mongodb-org
at version 2.6.6 through Synaptic Package Manager.
13. I checked all mongodb packages were at the same version:
mongodump --version
mongorestore --version
mongo --version
mongod --version
mongos --version
# all returned 2.6.6
14. I then did a mongorestore
with each database dump eg:
mongorestore --db dname_01 /path/to/dump/dbname_01/
mongorestore --db dname_02 /path/to/dump/dbname_02/
It seems to have worked on all databases but fails on the admin
database:
assertion: 17415 Cannot restore users with schema version 1 to a system with server version 2.5.4 or greater
And the users
database threw some anomalies eg:
Restoring to users.pending_registrations without dropping. Restored data will be inserted without raising errors; check your server log
Restoring to users.roles without dropping. Restored data will be inserted without raising errors; check your server log
Restoring to users.users without dropping. Restored data will be inserted without raising errors; check your server log
15. I ran db.upgradeCheckAllDBs()
:
mongo
use admin
db.upgradeCheckAllDBs()
Checking database local
Checking collection local.startup_log
Checking collection local.system.indexes
Checking database dname_01
...
Checking database admin
Everything is ready for the upgrade!
true
from: http://docs.mongodb.org/manual/release-notes/2.6-upgrade/#preparedness
Upvotes: 3