Hi, I’ve been trying to create post-registration action that sends user data and connection details whenever a new user is created to my mongodb. But, it always seems to keep getting timed out. I’ve tried running tests on whether the code could run locally, and it does.
/**
- @param {Event} event - Details about newly created user.
*/
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();
}
};