@@ -7,27 +7,24 @@ if (!process.env.MONGODB_URI) {
77const uri = process . env . MONGODB_URI ;
88const options = { } ;
99
10- let client ;
11- let clientPromise : Promise < MongoClient > ;
10+ let client : MongoClient ;
1211
1312if ( process . env . NODE_ENV === "development" ) {
1413 // In development mode, use a global variable so that the value
1514 // is preserved across module reloads caused by HMR (Hot Module Replacement).
1615 let globalWithMongo = global as typeof globalThis & {
17- _mongoClientPromise ?: Promise < MongoClient > ;
16+ _mongoClient ?: MongoClient ;
1817 } ;
1918
20- if ( ! globalWithMongo . _mongoClientPromise ) {
21- client = new MongoClient ( uri , options ) ;
22- globalWithMongo . _mongoClientPromise = client . connect ( ) ;
19+ if ( ! globalWithMongo . _mongoClient ) {
20+ globalWithMongo . _mongoClient = new MongoClient ( uri , options ) ;
2321 }
24- clientPromise = globalWithMongo . _mongoClientPromise ;
22+ client = globalWithMongo . _mongoClient ;
2523} else {
2624 // In production mode, it's best to not use a global variable.
2725 client = new MongoClient ( uri , options ) ;
28- clientPromise = client . connect ( ) ;
2926}
3027
31- // Export a module-scoped MongoClient promise . By doing this in a
28+ // Export a module-scoped MongoClient. By doing this in a
3229// separate module, the client can be shared across functions.
33- export default clientPromise ;
30+ export default client ;
0 commit comments