添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

but it is giving me this error here:

TypeError: Cannot read properties of undefined (reading 'startsWith')

What do you think it could be wrong?

I am using this code for Nextjs

The name startsWith looks like a field from a $graphLookup stage.

I suspect that you have some logic error in the code that generates a dynamic $graphLookup with a null object.

I have doubts that the issue is in the connect code you shared.

The URI is good… tested and got connection OK from another file app code.

This error is trigger from a page requesting the connection from the utils page…

mport { 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,
          

The more I think about that issue the less confident I feel about my $graphLookup thing. If there was an issue with it, I suspect you would get a server error rather than a type error.

Despite

Edgar_Lindo:

The URI is good… tested and got connection OK from another file app code

It would be helpful to see that URI since some application do not use exactly the same format.

Error: Cannot read properties of undefined (reading 'connection')
[nodemon] app crashed - waiting for file changes before starting...
const mongoose = require("mongoose");
const connectDB = async () => {
  const conn = await mongoose
    .connect(process.env.MONGO_URI, {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    .catch((err) => {
      console.log("error: ", err);
  console.log(`Mongoose Connected: ${conn.connection.host}`.cyan.underline.bold);
module.exports = connectDB;