Reputation: 1
In my web application, it works most of the time, but occasionally I get a 500 error, and sometimes I don’t. It works completle in local server, but the preblem is in the website that use MongoDB atlas. My app is in svelte/sveltikit and typescript.
Example: I am logged into the app and can log out and register a new user; it works 90% of the time. However, sometimes, when I logged out and want register a new user’s, ican can navigare to the register-page, enter the information and whene i click register I get an error 500.
I'm not sure why this error occurs, but the message is coming from the server:
MongoTopologyClosedError: Topology is closed
at processWaitQueue (/var/task/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/sdam/topology.js:509:46)
at Topology.selectServer (/var/task/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/sdam/topology.js:280:9)
at Topology.<anonymous> (/var/task/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/sdam/topology.js:41:94)
at node:internal/util:432:7
at new Promise (<anonymous>)
at Topology.selectServerAsync (node:internal/util:418:12)
at executeOperationAsync (/var/task/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/operations/execute_operation.js:77:35)
at /var/task/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/operations/execute_operation.js:12:45
at maybeCallback (/var/task/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/utils.js:270:21)
at executeOperation (/var/task/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/operations/execute_operation.js:12:38) {
[Symbol(errorLabels)]: Set(0) {}
}
My MongoDB file:
const client = new MongoClient(URI);
export async function connect() {
await client.connect();
}
export async function disconnect() {
await client.close();
}
export function getDB() {
return client.db();
}
I am new with MongoDB and web application.
I’ve tried numerous solutions without success, Like: Add &connectTimeoutMS=50000&socketTimeoutMS=50000 to the URI link to Mongo Atlas
I have read about changeing MongoClient:
const client = MongoClient(URI, { useNewUrlParser: true, useUnifiedTopology: true });
But i get an error in VSCode under useNewUrlParser:
Object literal may only specify known properties, and 'useNewUrlParser' does not exist in type 'MongoClientOptions'.ts(2353)
Any ideas on how to fix it?
Upvotes: 0
Views: 98