# Auth0 not connecting to MongoDB

**URL:** <https://community.auth0.com/t/auth0-not-connecting-to-mongodb/95472>\
**Category:** Get Help\
**Tags:** custom-database-connections, connections\
**Created:** [December 1, 2022, 1:27pm UTC](https://community.auth0.com/t/auth0-not-connecting-to-mongodb/95472 "2022-12-01T13:27:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaun1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shaun1/32/33837_2.png) [@shaun1](https://community.auth0.com/u/shaun1)\
**Post date:** [December 1, 2022, 1:27pm UTC](https://community.auth0.com/t/auth0-not-connecting-to-mongodb/95472/1 "2022-12-01T13:27:00Z")

</div>

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](https://www.youtube.com/watch?v=TXnDFU4sG0A)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 7, 2022, 5:13pm UTC](https://community.auth0.com/t/auth0-not-connecting-to-mongodb/95472/3 "2022-12-07T17:13:16Z")

</div>

Hi @shaun1,

Welcome to the Auth0 Community!

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 30, 2023, 9:38pm UTC](https://community.auth0.com/t/auth0-not-connecting-to-mongodb/95472/4 "2023-01-30T21:38:54Z")

</div>

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