In the Product Environment, Not loading data from MongoDB !!
Unanswered
ali argndgn posted this in #help-forum
import mongoose from "mongoose";
const URI = process.env.MONGO_URI;
if (!URI) {
throw new Error(
"Please define the MONGODB_URI environment variable inside .env.local"
);
}
let cached = global.mongoose;
if (!cached) {
cached = global.mongoose = { conn: null, promise: null };
}
async function dbConnect() {
if (cached.conn) {
console.log("cached db");
return cached.conn;
}
if (!cached.promise) {
const options = {
useNewUrlParser: true,
useUnifiedTopology: true,
ssl: true,
tlsAllowInvalidCertificates: true,
dbName: "HrDB",
};
cached.promise = mongoose.connect(URI, options).then((mongoose) => {
console.log("new db");
return mongoose;
});
}
try {
cached.conn = await cached.promise;
} catch (e) {
cached.promise = null;
throw e;
}
return cached.conn;
}
export default dbConnect;
No problem in local environment
When I put it in the product environment, it works normally for a while. Then it doesn't load the data from mongoDB
**After a while, the database stops responding. And timeout error returns.
const URI = process.env.MONGO_URI;
if (!URI) {
throw new Error(
"Please define the MONGODB_URI environment variable inside .env.local"
);
}
let cached = global.mongoose;
if (!cached) {
cached = global.mongoose = { conn: null, promise: null };
}
async function dbConnect() {
if (cached.conn) {
console.log("cached db");
return cached.conn;
}
if (!cached.promise) {
const options = {
useNewUrlParser: true,
useUnifiedTopology: true,
ssl: true,
tlsAllowInvalidCertificates: true,
dbName: "HrDB",
};
cached.promise = mongoose.connect(URI, options).then((mongoose) => {
console.log("new db");
return mongoose;
});
}
try {
cached.conn = await cached.promise;
} catch (e) {
cached.promise = null;
throw e;
}
return cached.conn;
}
export default dbConnect;
No problem in local environment
When I put it in the product environment, it works normally for a while. Then it doesn't load the data from mongoDB
**After a while, the database stops responding. And timeout error returns.
4 Replies
Where do you host?
Azure Devops
isn't it a build pipeline to build a Docker image? where do you deploy the image? Container Apps?
Docker