Skip to main content

mongoHandler

function mongoHandler(uri: string, config: Object = {})
async

Connects to a MongoDB database using Mongoose.

Returns: Promise<void>

  • Resolves when connected, exits process on failure.
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
uristringMongoDB connection URI.
configObject✔️Additional Mongoose connection options.
See the official mongoose package documentation for more details:

Throws:

Will log an error and exit the process if the connection fails.
See:

mongoHandler("mongodb://localhost:27017/mydb", { useNewUrlParser: true, useUnifiedTopology: true });