0

This is the error on my screen This is my console

this my address mongo :

MONGODB_URI= mongodb://localhost:27017/sinema

this page util/mongodb.js `

import mongoose from 'mongoose';
const MONGODB_URI = process.env.MONGODB_URI;
if (!MONGODB_URI) {
  throw new Error("Your mongodb uri is not defined!");
}
let cached = global.mongoose;
if (!cached) {
  cached = global.mongoose = { conn: null, promise: null };
}
export async function connectToDatabase() {
  if (cached.conn) {
    return cached.conn;
  }
  if (!cached.promise) {
    const opts = {
      useNewUrlParser: true,
      useUnifiedTopology: true,
      bufferCommands:false,
      bufferMaxWntries: 0 ,
      useFindAndModify: false,
      useCreateIndex: true
    };

    cached.promise = mongoose.connect(MONGODB_URI, opts).then((client) => {
      return client
    });
  }
  cached.conn = await cached.promise;

  return cached.conn;
}

`

` this my index page


export async function getServerSideProps(context) {
  const client = await connectToDatabase();

  const isConnected = await client.connections[0].readyState;

  return {
    props: {
      isConnected,
    },
  };
}

`

I tried version 5 and 6 and the addresses MONGODB_URI= mongodb://127.0.0.1:27017/sinema And mongodb://localhost:27017

I tried but nothing changed

0 Answers0