How to connect 2.6 mongo shell to 2.4.9 mongod?
Environment
-
Linux Mint 17.1
-
localhost
- MongoDB default port
27017
- No username or password required to connect the script.
Background
I installed MongoDB
with:
apt-get install mongodb-10gen=2.4.9
Then I pinned the package so that no updates were applied to it:
echo "mongodb-10gen hold" | sudo dpkg --set-selections
Desired Behaviou r
I want to upgrade to the latest version of MongoDB and see the official guide for this process:
http://docs.mongodb.org/manual/release-notes/2.6-upgrade
The beginning of this state says:
To start the upgrade procedure, connect the 2.6 mongo shell to MongoDB 2.4 mongos or mongod and run db.upgradeCheckAllDBs () to check your dataset for compatibility.
Question
How am I connect a 2.6 mongo shell
on 2.4.9 mongod
?
I would suggest that somehow I just need to install 2.6 mongo shell
and run it, but:
- I don't know how to do this and
- I don't want to break anything.
I have made the mongodump
entire database, so I have a backup.
I tried to install mongo
2.6 individually, but it caused other packages to be marked for removal. I ended up just uninstalling the old packages and reinstalling the new ones, and have included the process here for reference.
Some of the steps below did not help, but I have included them and their results in the documentation of what has been tried. I have previously done mongodump
all databases, so I had a backup.
The end result is that everything currently works as "working" apart from restoring the database admin
.
01. Turn offmongod
mongo
use admin
db.shutdownServer()
from: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
02. Removed the "pinned package" state mongodb-10gen
with
echo "mongodb-10gen install" | sudo dpkg --set-selections
from: https://help.ubuntu.com/community/PinningHowto
03. Then I tried to install the latter 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 has been updated:
mongo --version
MongoDB shell version: 2.6.6
05. But then I could not 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 view the apt-get install / uninstall history:
less /var/log/apt/history.log
and received:
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 packages mongodb-10gen
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 copy of a directory that could not be deleted, i.e. /var/lib/mongodb
:
sudo cp -avr /var/lib/mongodb/ /home/
10. And then delete it.
cd /var/lib/
sudo rm -rf mongodb/
11. I was looking for packages left mongodb-10gen
:
dpkg --get-selections | grep "mongodb-10gen"
which didn't return anything.
12. I installed mongodb-org
in version 2.6.6 via Synaptic Package Manager.
13. I checked that all mongodb packages were in the same version:
mongodump --version
mongorestore --version
mongo --version
mongod --version
mongos --version
# all returned 2.6.6
14. Then I did a mongorestore
with every dump dump, for example:
mongorestore --db dname_01 /path/to/dump/dbname_01/
mongorestore --db dname_02 /path/to/dump/dbname_02/
It seems to work with all databases, but the database fails admin
:
assertion: 17415 Cannot restore users with schema version 1 to a system with server version 2.5.4 or greater
And users
some anomalies were found in the database , for example:
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
I know you managed to solve your question, but the following link helped me and thought I could post it here for future reference and if anyone else finds a hard-to-do modernization of mongodb:
http://blog.lecstor.com/mongodb-upgrade-24-to-26-in-debian
EDIT: More appropriate answer, quoting the link above:
You need to download the tar version of MongoDB and start the shell directly 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
You also need to use the admin database to run the check, 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