Hello
I only started using mongodb about a month ago so I’m not sure if this is the right place to ask my question.
When I upload the next js site to varcel I receive this error from time to time
err: Cursor session id (------ - -------=) is not the same as the operation contexts session id (none)
Note (the number of results is approximately 500)
Api Code
const getBrands = async (req, res) => {
try {
const db = (await clientPromise).db();
const brands = await db.collection("brands").find().toArray();
res.json({ brands });
} catch (err) {
return res.status(500).json({ err: err.message });
}
};
connection string :
import { MongoClient } from "mongodb";
const uri = process.env.MONGO_URI;
const options = {
useUnifiedTopology: true,
useNewUrlParser: true,
};
let client;
let clientPromise;
if (!process.env.MONGO_URI) {
throw new Error("Please add your Mongo URI to .env.local");
}
if (process.env.NODE_ENV === "development") {
if (!global._mongoClientPromise) {
client = new MongoClient(uri, options);
global._mongoClientPromise = client.connect();
}
clientPromise = global._mongoClientPromise;
} else {
client = new MongoClient(uri, options);
clientPromise = client.connect();
}
export default clientPromise;