Skip to content

Commit a36257d

Browse files
authored
add JSDoc to dbConnect() function [ GSSOC'26 ] (JhaSourav07#2003)
## Description Adds JSDoc to `dbConnect()` documenting the Edge runtime restriction, the `MONGODB_URI` requirement, return value, and usage example. Brings it in line with the `dbDisconnect()` documentation style already present in the same file. Fixes JhaSourav07#2001 ## Pillar - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A — documentation only, no behavioural changes. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. - [x] My commits follow the Conventional Commits format. - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have starred the repo. - [x] I have made sure that I have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard. - [ ] (Recommended) I joined the CommitPulse Discord community.
2 parents c0ec5a6 + 39bf401 commit a36257d

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)