# SandboxTimeoutError in custom mongo database

**URL:** <https://community.auth0.com/t/sandboxtimeouterror-in-custom-mongo-database/127217>\
**Category:** Get Help\
**Tags:** custom-database-connections, connections\
**Created:** [February 13, 2024, 2:09pm UTC](https://community.auth0.com/t/sandboxtimeouterror-in-custom-mongo-database/127217 "2024-02-13T14:09:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ortieez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ortieez/32/49550_2.png) [@ortieez](https://community.auth0.com/u/ortieez)\
**Post date:** [February 13, 2024, 2:09pm UTC](https://community.auth0.com/t/sandboxtimeouterror-in-custom-mongo-database/127217/1 "2024-02-13T14:09:12Z")

</div>

Hello, I went through all possible forum posts with the same issue of: SandboxTimeoutError: Request to Webtask exceeded allowed execution time. And still no help.

- My Nodejs tenant is set to: Node version 18
- I tried changing MongoDB driver from 3.1.0 to 4.1.0 to 5.7.0 and even used the `require('mongodb').Mongoclient` without a version
- I tried removing the code and putting there “console.log(“hello”);” and looking into the Realtime logs and nothing there.
- I tried putting the password into encrypted configuration and using that
- I tried using the password in the string.
- I created the database with name “db-name” and created the “users” collection.
- I followed the blog post tutorial to the point.

This is the configuration for create user script:

```javascript
function create(user, callback) {
  const bcrypt = require('bcrypt');
  const MongoClient = require('mongodb@5.7.0').MongoClient;
  const client = new MongoClient('mongodb+srv://<username>:' + configuration.MONGO_PASSWORD + '@<url>.mongodb.net/?retryWrites=true&w=majority');

  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);
        });
      });
    });
  });
}

```

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![abdrah](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/abdrah/32/49411_2.png) [@abdrah](https://community.auth0.com/u/abdrah)\
**Post date:** [April 14, 2024, 3:34am UTC](https://community.auth0.com/t/sandboxtimeouterror-in-custom-mongo-database/127217/2 "2024-04-14T03:34:13Z")

</div>

Hi, I had the same issue, you need to change your runtime from 18 to 16 and in your script change

```auto
 const MongoClient = require('mongodb@5.7.0').MongoClient;

```

to

```auto
 const MongoClient = require('mongodb@4.1.0').MongoClient;

```

---

<div class="post-metadata">

**Author:** ![dmitry](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dmitry/32/13487_2.png) [@dmitry](https://community.auth0.com/u/dmitry)\
**Post date:** [June 6, 2024, 3:57am UTC](https://community.auth0.com/t/sandboxtimeouterror-in-custom-mongo-database/127217/3 "2024-06-06T03:57:50Z")

</div>

See my post in another thread. The fix is to use Promises instead of callbacks for MongoDB calls starting with Node 18 and Mongo 5.x  
I can confirm this works and fixes the problem. I’m able to use latest Mongo 5.x client and Node 18.]([Connecting Auth0 to MongoDB - #29 by dmitry](https://community.auth0.com/t/connecting-auth0-to-mongodb/55081/29))

---

<div class="post-metadata">

**Author:** ![danilo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/danilo/32/59725_2.png) [@danilo](https://community.auth0.com/u/danilo)\
**Post date:** [November 5, 2024, 1:25pm UTC](https://community.auth0.com/t/sandboxtimeouterror-in-custom-mongo-database/127217/4 "2024-11-05T13:25:40Z")

</div>

Thank you!! \<3 Works perfect

---

<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:** [April 2, 2025, 11:28am UTC](https://community.auth0.com/t/sandboxtimeouterror-in-custom-mongo-database/127217/5 "2025-04-02T11:28:24Z")

</div>

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