MongoDB Connection issue with load balancer and driver incompatibility

All the methods are running into the error - The server is being accessed through a load balancer, but this driver does not have load balancing enabled

Following is my create script. Any help is appreciated here.

function create(user, callback) {
  const bcrypt = require('bcrypt');
  const MongoClient = require('mongodb@3.1.4').MongoClient;
  const client = new MongoClient('mongodb+srv://user:pass@cluster.ems0gvj.mongodb.net/?retryWrites=true&w=majority');

  client.connect(function (err) {
    if (err) return callback(err);

    const db = client.db('auth0-dev');
    const users = db.collection('users');

    users.findOne({ email: user.email }, function (err, withSameMail) {
      if (err || withSameMail) {
        client.close();
        return callback(err || new Error('the user already exists'));
      }

      bcrypt.hash(user.password, 10, function (err, hash) {
        if (err) {
          client.close();
          return callback(err);
        }

        user.password = hash;
        user.email_verified = false;
        users.insert(user, function (err, inserted) {
          client.close();

          if (err) return callback(err);
          callback(null);
        });
      });
    });
  });
}

1 Like

Hi @shaswat607,

It looks like you are using an older version of the mongodb node client. Can you try upgrading to see if it solves the issue?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.