# PostUserRegistration action creating a mongo document

**URL:** <https://community.auth0.com/t/postuserregistration-action-creating-a-mongo-document/109988>\
**Category:** Get Help\
**Tags:** user-profile, user-management\
**Created:** [June 26, 2023, 6:55pm UTC](https://community.auth0.com/t/postuserregistration-action-creating-a-mongo-document/109988 "2023-06-26T18:55:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HeyItsKito](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/heyitskito/32/48335_2.png) [@HeyItsKito](https://community.auth0.com/u/HeyItsKito)\
**Post date:** [June 26, 2023, 6:55pm UTC](https://community.auth0.com/t/postuserregistration-action-creating-a-mongo-document/109988/1 "2023-06-26T18:55:45Z")

</div>

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 ?

```auto
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();
};

```

---

<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:** [June 29, 2023, 12:15pm UTC](https://community.auth0.com/t/postuserregistration-action-creating-a-mongo-document/109988/3 "2023-06-29T12:15:31Z")

</div>

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.

---

<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:** [July 13, 2023, 12:16pm UTC](https://community.auth0.com/t/postuserregistration-action-creating-a-mongo-document/109988/4 "2023-07-13T12:16:12Z")

</div>

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