MongoDB Post User Registration always timing out

Here’s the code, sorry about it:

/**
 * @param {Event} event - Details about newly created user.
 */
// Import the MongoDB driver
const { MongoClient } = require('mongodb');

exports.onExecutePostUserRegistration = async (event, api) => {
  const newUser = { user: event.user, connection: event.connection };

  const client = new MongoClient(event.secrets.MONGO_DB, { useNewUrlParser: true });

  try {
    await client.connect();

    const usersCollection = client.db('test').collection('users');

    const insertResult = await usersCollection.insertOne(newUser);
    console.log(`Inserted ${insertResult.insertedCount} document into the database.`);

  } catch (err) {
    console.error('Error inserting data into MongoDB:', err);
  } finally {
    await client.close();
  }
};