Auth0 not connecting to MongoDB

I am encountering an error with linking my custom database (mongoDB) to the application i’ve built. Whenever I run the create script, with the proper mongoDB credentials filled, I get this error: [MongoError] 354 - The server is being accessed through a load balancer, but this driver does not have load balancing enabled

For instructions on setting this all up, I followed this video: Custom Databases: Connecting Auth0 to MongoDB - YouTube

Hi @shaun1,

Welcome to the Auth0 Community!

Are you using the standard MongoDB script template from the dashboard?

function create(user, callback) {
  const bcrypt = require('bcrypt');
  const MongoClient = require('mongodb@3.1.4').MongoClient;
  const client = new MongoClient('mongodb://user:pass@localhost');

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

    const db = client.db('db-name');
    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;
        users.insert(user, function (err, inserted) {
          client.close();

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

If not, could you please provide an example script with any sensitive data removed?

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