I am trying to create a MERN app and containerize it with docker and manage the containers using kubernetes (minikube).
When I try to run the nodejs container it logs the following error
Server v8 up and running on port 5000 !
MongoTimeoutError: Server selection timed out after 10000 ms
at Timeout._onTimeout (/home/app/node_modules/mongodb-core/lib/sdam/topology.js:773:16)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
[Symbol(mongoErrorContextSymbol)]: {}
}
The code at server.js is as follows:
const express = require("express");
const mongoose = require("mongoose");
const app = express();
// the connection string when using username and password in mongodb-server
// mongodb://${process.env.MONGO_DB_USERNAME}:${process.env.MONGO_DB_PASSWORD}@mongodb-service:27017/exam?authSource=${process.env.MONGO_DB_USERNAME}
mongoose
.connect("mongodb://mongodb-service/exam", {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log(`MongoDB successfully connected`))
.catch((err) => console.log(err));
The logs in mongodb container are as follows:
{"t":{"$date":"2022-12-16T14:28:58.316+00:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"LogicalSessionCacheRefresh","msg":"Slow query","attr":{"type":"command","ns":"config.system.sessions","command":{"createIndexes":"system.sessions","v":2,"indexes":[{"key":{"lastUse":1},"name":"lsidTTLIndex","expireAfterSeconds":1800}],"ignoreUnknownIndexOptions":false,"writeConcern":{},"$db":"config"},"numYields":0,"reslen":114,"locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":5}},"FeatureCompatibilityVersion":{"acquireCount":{"r":5,"w":1}},"ReplicationStateTransition":{"acquireCount":{"w":5}},"Global":{"acquireCount":{"r":5,"w":1}},"Database":{"acquireCount":{"r":4,"w":1}},"Collection":{"acquireCount":{"r":5,"w":1}},"Mutex":{"acquireCount":{"r":8}}},"storage":{},"protocol":"op_msg","durationMillis":529}}
If I should provide more details please tell me
Thanks in advance