SoftTimur
SoftTimur

Reputation: 5540

Upgrade MongoDB 2.6.12 to 4.2 in Ubuntu 16.04

I have a web application using MongoDB (Version 2.6.12), hosted in a (Ubuntu 16.04) server of DigitalOcean.

I like to use Robo 3T to connect to the remote database and do simple queries.

Now, I need to undertake queries containing like $lookup, they told me that MongoDB Version 2.16.12 does not support that. So I need to seriously backup my database and upgrade MongoDB.

When I look at this guide, it seems too complicated to me: I don't know if I have MongoDB drivers, shared clusters, standalone instances, etc.

Someone also says that we need to do it step by step: upgrade to a certain version, then to 4.2.

May I rely on e.g. this approach? I would like to make sure before actions...

Edit 1: Here is a part of code in models/Users.js:

addAccountWOCheck(profile) {
    return new Promise((resolve, reject) => {
        var x = {}; x[profile.provider] = profile;
        var collection = new this.user(x);
        this.setPassword(x, profile.password);
        delete collection.local.password;
        delete collection.local.passwordRepeat 
        collection.save((err, data) => { if (err) throw (err); resolve(data) }) // {JavaScript}: only "collection.save()" does not work here
    })
}

setPassword(collection, password) {
    var salt = crypto.randomBytes(16).toString('hex');
    var hash = crypto.pbkdf2Sync(password, salt, 1000, 64, 'SHA1').toString('hex');
    collection.local.hash = hash;
    collection.local.salt = salt
}

Upvotes: 1

Views: 1058

Answers (1)

Joe
Joe

Reputation: 28356

https://stackoverflow.com/a/13078276/702977 is 8 years old, so the links may not work anymore.

MongoDB drivers are usually libraries that you use in your application to handle connecting to the database to query, insert, etc. If you upgrade the database from 2.6 to 4.2 without upgrading the driver, it probably won't be able to connect. It would be best to upgrade the driver first, then the database.

If you are going to use mongodump to backup your data and mongorestore to insert it into the upgraded database, you don't need to upgrade in steps.

  • backup the data set using mongodump
  • uninstall the existing version
  • follow the installation steps for MongoDB 4.2
  • restore the data with mongorestore

One of the major changes between 2.6 and the newer versions is authentication. MongoDB-CR is not supported at all in 4.2, so you will probably need to recreate all of your users once you upgrade.

MMAP is also gone, but that shouldn't be a problem when you use the backup/restore method to upgrade.

Upvotes: 1

Related Questions