Skip to content

Commit 39bf401

Browse files
committed
docs(mongodb): add JSDoc to dbConnect() function
1 parent a69a12d commit 39bf401

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

lib/mongodb.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ let cached = global.mongoose;
1313
if (!cached) {
1414
cached = global.mongoose = { conn: null, promise: null };
1515
}
16-
16+
/**
17+
* Connects to the MongoDB database and returns the cached connection.
18+
*
19+
* Reuses an existing connection if one is already established.
20+
* Automatically resets the cache if the connection drops.
21+
*
22+
* @throws {Error} If called from the Edge runtime.
23+
* @throws {Error} If `MONGODB_URI` environment variable is not defined.
24+
* @returns The active Mongoose connection instance.
25+
*
26+
* @example
27+
* const db = await dbConnect();
28+
*/
1729
async function dbConnect() {
1830
if (process.env.NEXT_RUNTIME === 'edge') {
1931
throw new Error('MongoDB is not supported in the Edge runtime. Use the Node.js runtime.');

0 commit comments

Comments
 (0)