Hello I have been trying to fix this for a week. It worked at first, but now it just stopped. I want to connect my vue app to a mongodb hosted by them and using this code
const express = require("express");
const mongodb = require("mongodb");
const router = express.Router();
router.get("/", async(req, res) => {
const gottenData = await doStuff();
res.send(await gottenData.find({}).toArray());
});
async function doStuff() {
console.log("connecting");
const client = await mongodb.MongoClient.connect(
"mongodb+srv://<NAME>:<PASSWORD>@cluster0.9tlzg.mongodb.net/database?retryWrites=true&w=majority", { useNewURLParser: true }
);
return client.db("database").collection("collection");
}
module.exports = router:
I am attaching screenshot of my mongodb setup as well

You should create a client and then .connect separately.
const express = require("express");
const mongodb = require("mongodb");
const router = express.Router();
router.get("/", async(req, res) => {
const gottenData = await doStuff();
res.send(await gottenData.find({}).toArray());
});
async function doStuff() {
console.log("connecting");
const client = new mongodb.MongoClient('mongodb+srv://<NAME>:<PASSWORD>@cluster0.9tlzg.mongodb.net/database?retryWrites=true&w=majority', { useNewURLParser: true });
await client.connect();
return client.db("database").collection("collection");
}
module.exports = router:
Edit: see this for docs https://docs.mongodb.com/drivers/node/current/fundamentals/connection/