mongodb.js
import { MongoClient } from 'mongodb' const uri = process.env.MONGODB_URI const options = { useUnifiedTopology: true, useNewUrlParser: true, } let client let clientPromise if (!process.env.MONGODB_URI) { throw new Error('Add Mongo URI to .env.local') } client = new MongoClient(uri, options) clientPromise = client.connect() export default clientPromise
import the clientPromise
const client= await clientPromise; const db=client.db("blog"); const users = await db.collection("users").find({email:body.email}).toArray();