I am following this tutorial:
My code is:
import clientPromise from "../lib/mongodb";
export default async (req, res) => {
try {
const client = await clientPromise;
const db = client.db("Reports");
const collection = await db
.collection("Reports")
const report = await db
.collection("Reports")
.find({})
.toArray()
res.json(report);
} catch (e) {
console.error(e);
}
};
In my code the report after .toArray() returns my data within an array. However, I get this error:
TypeError: Cannot read properties of undefined (reading 'json')
It seems the data comes through to the array but then there is an issue returning it as json.