Client undefined Error in MongoDB Atlas API (Node.js)
export async function getViews(id: string) { try { await client.connect(); const collection = client.db(“views”).collection(“views”); const data = await collection.findOne({id}); if(!data) { return 0; } return data.views; } finally { await client.close(); } } This is my code. When it runs, it should return the views number of the according document in the collection “views” of […]