We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a69a12d commit 39bf401Copy full SHA for 39bf401
1 file changed
lib/mongodb.ts
@@ -13,7 +13,19 @@ let cached = global.mongoose;
13
if (!cached) {
14
cached = global.mongoose = { conn: null, promise: null };
15
}
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
+ */
29
async function dbConnect() {
30
if (process.env.NEXT_RUNTIME === 'edge') {
31
throw new Error('MongoDB is not supported in the Edge runtime. Use the Node.js runtime.');
0 commit comments