you could check out my repos here? The nest repo u...
# mongodb
a
you could check out my repos here? The nest repo uses postgres instead of mongo but I have a nextjs + mongodb repo as well. It's quite similar sans the need to asynchronously instantiate the mongodb db in your server and pass it as returned context if using the apollo server expess driver in Nestjs
then this repo is a nextjs monorepo with mongodb atlas
if you set up the database in nextjs with mongo it should look something like this fro the config file in the lib directory
Copy code
import { MongoClient, MongoClientOptions } from "mongodb";

// MongoClient is attached to the `global` object in development
// to prevent exhausting the database connection limit.

declare global {
  var client: MongoClient;
  var _mongoClientPromise: Promise<MongoClient>;
}
let client: MongoClient;
let clientPromise: Promise<MongoClient>;

const options: MongoClientOptions = {};
const mongoUri = process.env.DATABASE_URL ?? "";

if (process.env.NODE_ENV === "development") {
 if (!global._mongoClientPromise) {

    global.client = new MongoClient(mongoUri, options);
    global._mongoClientPromise = global.client.connect();
  }
  client = global.client;
  clientPromise = global._mongoClientPromise;
} else {
  client = new MongoClient(mongoUri, options);
  clientPromise = client.connect();
}

export default clientPromise;