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