initMongo
function initMongo(config: Object = {})
async
Connects to a MongoDB database using Mongoose.
Returns: Promise<Object>
- Resolves to the Mongoose connection when connected.
| PARAMETER | TYPE | OPTIONAL | DEFAULT | DESCRIPTION |
|---|---|---|---|---|
| config | Object | ✔️ | MongoDB connection configuration. | |
| config.uri | string | MongoDB connection URI. | ||
| config.mongooseConfig | Object | ✔️ | 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" });