Skip to main content

initMongo

function initMongo(config: Object = {})
async

Connects to a MongoDB database using Mongoose.

Returns: Promise<Object>

  • Resolves to the Mongoose connection when connected.
PARAMETERTYPEOPTIONALDEFAULTDESCRIPTION
configObject✔️MongoDB connection configuration.
config.uristringMongoDB connection URI.
config.mongooseConfigObject✔️Additional Mongoose connection options.
See the official mongoose package documentation for more details:

Throws: Error

Rejects if config.uri is missing or the connection fails.
See:

const mongoose = await initMongo({ uri: "mongodb://localhost:27017/mydb" });