I'm having trouble finding clear guidelines on how to handle database connections (specifically MongoDB) in an Azure function written in JavaScript.
According to a Microsoft document linked below, it's advised not to create a new connection for each invocation of the function. Instead, static variables in C# with .NET Framework Data Provider for SQL Server can be used, as client connection pooling is handled automatically. However, it doesn't explain how to apply this in JavaScript.
https://learn.microsoft.com/en-us/azure/azure-functions/manage-connections
One solution mentioned is to create a global variable to store the database client between invocations, although the author expresses uncertainty about whether this is the correct approach.
Has anyone implemented this method in a production environment or can provide insight on whether it's the right way to go?