File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { Db , MongoClient } from 'mongodb' ;
1+ import { Db , MongoClient , ServerApiVersion } from 'mongodb' ;
22
33import {
44 findOneFromDB as _findOneFromDB , insertInDb as _insertInDb , updateOneFromDb as _updateOneFromDb
55} from './inMemDB' ;
66
77const uri = process . env . MONGO_URI ;
88const dbName = process . env . MONGO_DB_NAME ;
9- const client = uri ? new MongoClient ( uri ) : null ;
109
1110let db : Db = null ;
1211let inMem = uri ? false : true ;
1312
1413const connectDb = async ( ) : Promise < void > => {
1514 try {
15+ if ( ! uri ) throw new Error ( "No URI" ) ;
16+ const client = new MongoClient ( uri , {
17+ serverApi : {
18+ version : ServerApiVersion . v1 ,
19+ strict : true ,
20+ deprecationErrors : true ,
21+ }
22+ } ) ;
1623 if ( ! client ) throw new Error ( "No client" ) ;
1724 await client . connect ( ) ;
1825 db = client . db ( dbName ) ;
You can’t perform that action at this time.
0 commit comments