Can’t connect to my mongdb database using mongoose (nodejs)

Im trying to connect to my database. Its working if i use mongodb compass but then im using mongoose to connect it doesn’t work.

I keep getting this error:

Mongoose connection error MongoServerSelectionError: Client network socket disconnected before secure TLS connection was established
    at Topology.selectServer (C:UsersgerarDesktopHtmlPractica-HolaMundohtmlPracticaAPIrestnode_modulesmongodblibsdamtopology.js:320:38)
    at async Topology._connect (C:UsersgerarDesktopHtmlPractica-HolaMundohtmlPracticaAPIrestnode_modulesmongodblibsdamtopology.js:204:28)
    at async Topology.connect (C:UsersgerarDesktopHtmlPractica-HolaMundohtmlPracticaAPIrestnode_modulesmongodblibsdamtopology.js:156:13)
    at async topologyConnect (C:UsersgerarDesktopHtmlPractica-HolaMundohtmlPracticaAPIrestnode_modulesmongodblibmongo_client.js:233:17)
    at async MongoClient._connect (C:UsersgerarDesktopHtmlPractica-HolaMundohtmlPracticaAPIrestnode_modulesmongodblibmongo_client.js:246:13)
    at async MongoClient.connect (C:UsersgerarDesktopHtmlPractica-HolaMundohtmlPracticaAPIrestnode_modulesmongodblibmongo_client.js:171:13)
    at async NativeConnection.createClient (C:UsersgerarDesktopHtmlPractica-HolaMundohtmlPracticaAPIrestnode_modulesmongooselibdriversnode-mongodb-nativecon
nection.js:320:3

This is my api.js file

const express = require("express");
const mongoose = require("mongoose");
const user = require("./user.controller");
const port = 3000;
const app = express();

app.use(express.json());

mongoose.connect(
  "mongodb+srv://geraboy:(password)@holamundocert.wfq1b.mongodb.net/miApp?retryWrites=true&w=majority&appName=HolaMundoCert"
);

mongoose.connection.on("connected", () => {
  console.log("Mongoose connected to MongoDB");

  app.listen(port, () =>
    console.log(`Starting server on port ${port}`)
  );
});

mongoose.connection.on("error", (error) => {
  console.log("Mongoose connection error", error);
});

app.get("/", user.list);
app.post("/", user.create);
app.get("/:id", user.get);
app.put("/:id", user.update);
app.patch("/:id", user.update);
app.delete("/:id", user.destroy);

This is my package.json

{
  "name": "apirest",
  "version": "1.0.0",
  "description": "",
  "main": "api.js",
  "scripts": {
    "start": "nodemon api.js"
  },
  "keywords": [],
  "author": "Gerardo Acedo",
  "license": "ISC",
  "dependencies": {
    "express": "^4.21.2",
    "mongodb": "^6.12.0",
    "mongoose": "^8.9.5"
  },
  "devDependencies": {
    "nodemon": "^3.1.9"
  }
}

I tried setting the IP network access to 0.0.0.0/0 on the mongodb cluster’s website, also tried adding my own IP direction.
Already created inbound and outbound permissions for port 27017.

Also tried setting my DNS to 8.8.8.8