File size: 386 Bytes
9cd6ddb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { MongoClient } from "mongodb";

const uri = process.env.MONGO_DB_URI;
const options = {
  useUnifiedTopology: true,
  useNewUrlParser: true,
};

let client: any;
let clientPromise: any;

if (!process.env.MONGO_DB_URI) {
  throw new Error("Add Mongo URI to .env.local");
}

client = new MongoClient(uri, options);
clientPromise = client.connect();

export default clientPromise;