I’m working on establishing a connection to MongoDB within an AWS Lambda function.
My question is whether the following code snippet effectively utilizes connection pooling, or if it always creates a single connection:
`JavaScript// Creating a MongoClient with a pool size
const client = await new MongoClient(uri, { minPoolSize: 10 }).connect();
// Switching to test database
connection = await mongoose.createConnection().setClient(client).useDB(‘test’);
const promises = ;
for (let i = 0; i < 5; i++) {
// Will this use a new connection from the pool or reuse an existing one?
promises.push(connection.model(“Message”).create(/* your message data */));
}
await Promise.all(promises);`