diff options
| author | Factiven <[email protected]> | 2023-04-14 00:14:12 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-04-14 00:14:12 +0700 |
| commit | 70fda74d27d9b55c9030932794daa25c1e6cf50d (patch) | |
| tree | 0c1f639be4e8ec1b960ba642b8e99c1485e83b1a /pages/lib/mongodb.js | |
| parent | Update 5th (diff) | |
| download | moopa-70fda74d27d9b55c9030932794daa25c1e6cf50d.tar.xz moopa-70fda74d27d9b55c9030932794daa25c1e6cf50d.zip | |
Update 6th
Diffstat (limited to 'pages/lib/mongodb.js')
| -rw-r--r-- | pages/lib/mongodb.js | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/pages/lib/mongodb.js b/pages/lib/mongodb.js deleted file mode 100644 index dbbf0dc..0000000 --- a/pages/lib/mongodb.js +++ /dev/null @@ -1,30 +0,0 @@ -// This approach is taken from https://github.com/vercel/next.js/tree/canary/examples/with-mongodb -import { MongoClient } from "mongodb"; - -if (!process.env.MONGODB_URI) { - throw new Error('Invalid/Missing environment variable: "MONGODB_URI"'); -} - -const uri = process.env.MONGODB_URI; -const options = {}; - -let client; -let clientPromise; - -if (process.env.NODE_ENV === "development") { - // In development mode, use a global variable so that the value - // is preserved across module reloads caused by HMR (Hot Module Replacement). - if (!global._mongoClientPromise) { - client = new MongoClient(uri, options); - global._mongoClientPromise = client.connect(); - } - clientPromise = global._mongoClientPromise; -} else { - // In production mode, it's best to not use a global variable. - client = new MongoClient(uri, options); - clientPromise = client.connect(); -} - -// Export a module-scoped MongoClient promise. By doing this in a -// separate module, the client can be shared across functions. -export default clientPromise; |