I am trying to use colyseus social package and I set MONGO_URI as expected via process.env.MONGO_URI in my index.ts but while colyseus server going to make a connection with mongodb it is getting default value(old value) although process.env.MONGO_URI updated to new value.
I tried to check it in connectDatabase method of index.ts in social module and console like :-
import { MONGO_URI } from "./env";
export async function connectDatabase(cb?: (err: MongoError) => void) {
// skip if already connecting or connected.
if (mongoose.connection.readyState !== 0) {
if (cb) cb(null);
return;
}
try {
console.log(process.env.MONGO_URI);// getting updated value
console.log(MONGO_URI);//getting old value
await mongoose.connect(MONGO_URI, { autoIndex: false, useNewUrlParser: true }, cb);
debug(`Successfully connected to ${MONGO_URI}`)
// reconnect if disconnected.
mongoose.connection.on('disconnected', () => connectDatabase());
} catch (e) {
console.error('Error connecting to database: ', e);
}
}
Please help it out . Thanks in advance