# TypeError: Cannot read properties of undefined (reading 'db')
So I have this portion of code that goes like this:
from this page here:
import { clientPromise } from "../utils/mongodb";
export async function getStaticProps() {
// await clientPromise;
// `await clientPromise` will use the default database passed in the MONGODB_URI
// However you can use another database (e.g. myDatabase) by replacing the `await clientPromise` with the following code:
//
const client = await clientPromise;
const dbs = client.db("parts");
//
// Then you can execute queries against your database like so:
// db.find({}) or any of the MongoDB Node Driver commands
return {
props: { db },
revalidate: 60,
};
}
const Inventory = ({ db }) => {
You might wanna add a console log and see what you get as client value. Also, it looks a little bit odd you dont call clientPromise with parenthesis- clientPromise()
at getStaticProps (webpack-internal:///./pages/inventory.js:30:23)
at async Object.renderToHTML (file://C:\Users\Edgar\Desktop\Stuff\Acode\nextprojectb\node_modules\next\dist\server\render.js:492:20)
at async doRender (file://C:\Users\Edgar\Desktop\Stuff\Acode\nextprojectb\node_modules\next\dist\server\base-server.js:901:38)
at async cacheEntry.responseCache.get.isManualRevalidate.isManualRevalidate (file://C:\Users\Edgar\Desktop\Stuff\Acode\nextprojectb\node_modules\next\dist\server\base-server.js:1006:28)
at async (file://C:\Users\Edgar\Desktop\Stuff\Acode\nextprojectb\node_modules\next\dist\server\response-cache.js:74:36)
This code is for Next.js the clientPromise is an import of the connection file for MongoDB under utils/mongodb.js