Moses Liao GZ
Moses Liao GZ

Reputation: 1608

Problems upgrading MongoDB

I have difficulty updating mongodb from version 2.0.6 to the current 2.4. Please help

Below is the log file that i get:

Tue May 14 08:02:03.339 [initandlisten] MongoDB starting : pid=1906 port=27017 dbpath=/mnt2/var/lib/mongodb/ 64-bit host=ip-10-131-65-73
Tue May 14 08:02:03.339 [initandlisten] db version v2.4.3
Tue May 14 08:02:03.339 [initandlisten] git version: fe1743177a5ea03e91e0052fb5e2cb2945f6d95f
Tue May 14 08:02:03.340 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Tue May 14 08:02:03.340 [initandlisten] allocator: tcmalloc
Tue May 14 08:02:03.340 [initandlisten] options: { dbpath: "/mnt2/var/lib/mongodb/" }
Tue May 14 08:02:03.347 [initandlisten] journal dir=/mnt2/var/lib/mongodb/journal
Tue May 14 08:02:03.347 [initandlisten] recover : no journal files present, no recovery needed
Tue May 14 08:02:03.554 [initandlisten] build index backendtemp.system.users { user: 1, userSource: 1 }
Tue May 14 08:02:03.557 [initandlisten] Duplicate key exception while trying to build unique index on backendtemp.system.users.  You most likely have user documents with duplicate "user" fields.  To resolve this, start up with a version of MongoDB prior to 2.4, drop the duplicate user documents, then start up again with the current version.
Tue May 14 08:02:03.557 [initandlisten] exception in initAndListen: 11000 E11000 duplicate key error index: backendtemp.system.users.$user_1_userSource_1  dup key: { : "ad", : null }, terminating
Tue May 14 08:02:03.557 dbexit: 
Tue May 14 08:02:03.557 [initandlisten] shutdown: going to close listening sockets...
Tue May 14 08:02:03.557 [initandlisten] shutdown: going to flush diaglog...
Tue May 14 08:02:03.557 [initandlisten] shutdown: going to close sockets...
Tue May 14 08:02:03.558 [initandlisten] shutdown: waiting for fs preallocator...
Tue May 14 08:02:03.558 [initandlisten] shutdown: lock for final commit...
Tue May 14 08:02:03.558 [initandlisten] shutdown: final commit...
Tue May 14 08:02:03.572 [initandlisten] shutdown: closing all files...
Tue May 14 08:02:03.573 [initandlisten] closeAllFiles() finished
Tue May 14 08:02:03.573 [initandlisten] journalCleanup...
Tue May 14 08:02:03.573 [initandlisten] removeJournalFiles
Tue May 14 08:02:03.575 [initandlisten] shutdown: removing fs lock...
Tue May 14 08:02:03.575 dbexit: really exiting now

Upvotes: 2

Views: 1392

Answers (3)

William Ledoux
William Ledoux

Reputation: 146

If you can't or won't downgrade mongodb, you can also use mongodump and then mongorestore. You will loose every mongo user but get your data back.

mongodump --dbpath OLD_DB_PATH -d DATABASENAME -o /tmp/dumps
mongorestore --dbpath NEW_DB_PATH -d DATABASENAME /tmp/dumps/DATABASENAME/
  1. As always with mongo, be careful about the permissions of the restored files if you do not run the above commands as the mongodb user.
  2. This won't work if your current mongodb version is at least 3.0 because the dbpath option has been removed, forcing you to have a running mongod on the dbpath to run those commands, which is precisely what's not working right now...
  3. In case you have problems, you may try to run mongod --dbpath NEW_DB_PATH --repair

Upvotes: 0

Hertzel Guinness
Hertzel Guinness

Reputation: 5940

Small script pasties regarding this (ubuntu):
NOTE: replace CAPS by you vars...

  • If its a sharded cluster, always make sure balancer is off before this kinda things.
  • Run sudo apt-get install mongodb-10gen=2.2.7 <- reduce version, probably want 2.2.7 its the latest pre-2.4 (as of May 2014)
  • Remember to restart mongod config server
  • connect using mongoCONFIG_SERVER_HOST:CONFIG_SERVER_PORT/admin # <- connect to mongo config server,
    • db.system.users.find().sort({_id:1}) <- would display the admin users sorted by id which is like sorting ascending by time here, coz its bson.
    • db.system.users.remove({_id : ObjectId('ID_TO_BE_REMOVED')}) <- remove the culprit, USE WITH CARE. if you not sure, start by creating another admin user for backup.
  • Quit the mongo console
  • Run sudo apt-get install mongodb-10gen <- will upgrade back to latest 2.4.X. not it will not upgrade to 2.6 (which is good, coz you want to ensure 2.4 is working first) because its a different apt-get package for 2.6 (mongodb-org).

HTH

Upvotes: 1

Ben-Hur Langoni Junior
Ben-Hur Langoni Junior

Reputation: 2175

In version 2.4 MongoDB introduced a role-based access control which requires uniqueness of the user in user privilege documents per database. Previous versions of MongoDB didn't have this requirement, so that your database may have duplicate user entries in system.users.

You can either:

  1. Downgrade MongoDB to an older version, remove the duplicate entries and upgrade MongoDB again, or:
  2. If you are in a development environment and/or don't care about your data (i.e. loosing your entire database), you can remove the database files manually through your filesystem. On Linux they are usually located at "/var/lib/mongodb/name-of-the-database". Try starting MongoDB after that and you are cool.

See: MongoDB 2.4 Upgrade Recommendations and Checklist

Upvotes: 3

Related Questions