So I am trying to use this piece of code here to extract information from MongoDB and pass it down the line from getStaticProps into the rest of the code…
import { managerdb } from "../utils/connect";
export const getStaticProps = async () => {
const { db } = await managerdb.connect();
const data = await db
.collection("parts")
.find({})
.sort({})
.limit(1000)
.toArray();
return {
props: {
data: JSON.parse(JSON.stringify(data)), // why?
},
revalidate: 60,
};
};
Then… from my utils folder I got something like this:
import { MongoClient } from "mongodb";
const createConnection = () => {
// let current = null;
const client = new MongoClient(process.env.MONGODB_URI);
return async function run() {
await client.connect();
};
};
export const managerdb = createConnection();
the .env string is good… but I am getting eror…
TypeError: Cannot read properties of undefined (reading 'startsWith')
Would anybody know what could possibly be wrong?
