PostUserRegistration action creating a mongo document

I am trying to create a new user document in my mongoDB after a user signs up for the first time. I saw on another post that this code could be used to insert a document but the execution time gets exceeded. Im guessing its not able to connect successfully but not sure why. I Have my secret variable as “mongodb://localhost:27017/{myapp}” and i have mongodb installed as a dependency. Is there any way to tell if its getting connected ?

const { MongoClient } = require("mongodb");
exports.onExecutePostUserRegistration = async (event, api) => {
   const newUser = { username:event.user.username, authSub: event.user.user_id };
  const client = await MongoClient.connect(event.secrets.MONGO_DB);
  const db = client.db();
  await db.collection("users").insertOne(newUser);
  client.close();
};

Hi @HeyItsKito,

Welcome to the Auth0 Community!

The connection URL of your database (the param passed to connect) couldn’t be localhost. Where are you hosting the database? It should be a publicly available endpoint that the Auth0 server can reach out to and connect with.

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