cache mongo client - not sure if it makes a diff 🤷

This commit is contained in:
Thomas Ruoff
2021-12-08 23:42:53 +01:00
committed by Thomas Ruoff
parent 451f03549d
commit f1ff6b0a41

View File

@@ -6,11 +6,14 @@ import { MongoDBAdapter } from "@next-auth/mongodb-adapter"
import { MONGO_URI, MONGODB_OPTIONS } from "../../../db" import { MONGO_URI, MONGODB_OPTIONS } from "../../../db"
import { MongoClient } from "mongodb"; import { MongoClient } from "mongodb";
let mongooseConnection: Mongoose; let client: MongoClient;
async function getMongoClient() { async function getMongoClient() {
const client = new MongoClient(MONGO_URI, MONGODB_OPTIONS); if (!client) {
await client.connect(); client = new MongoClient(MONGO_URI, MONGODB_OPTIONS);
await client.connect();
}
return client; return client;
} }