Help me members . please

Hii team ,
i am learning backend and trying to use mongo on localhost . but is throwing error i attached image below . please help me and tell me why this error is coming and how i can avoid in feature this problem.
using window As OS, using nodejs 20v , and here is DB_URL : “mongodb://”.`

Server started at 27017
Error in connecting to database

D:\vs code pratice\Backend pro\E-commerce\node_modules\mongoose\lib\connection.js:896
    err = new ServerSelectionError();    
MongooseServerSelectionError: connection <monitor> to closed
    at _handleConnectionErrors (D:\vs code pratice\Backend pro\E-commerce\node_modules\mongoose\lib\connection.js:896:11)
    at NativeConnection.openUri (D:\vs code pratice\Backend pro\E-commerce\node_modules\mongoose\lib\connection.js:847:11) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) {
      '' => ServerDescription {
        address: '',
        type: 'Unknown',
        hosts: [],
        passives: [],
        arbiters: [],
        tags: {},
        minWireVersion: 0,
        maxWireVersion: 0,
        roundTripTime: -1,
        minRoundTripTime: 0,
        lastUpdateTime: 160627453,
        lastWriteDate: 0,
        error: MongoNetworkError: connection <monitor> to closed
            at Connection.onClose (D:\vs code pratice\Backend pro\E-commerce\node_modules\mongodb\lib\cmap\connection.js:109:22)
            at Socket.emit (node:events:519:28)
            at TCP.<anonymous> (node:net:338:12) {
          [Symbol(errorLabels)]: Set(1) { 'ResetPool' },
          [cause]: undefined
        topologyVersion: null,
        setName: null,
        setVersion: null,
        electionId: null,
        logicalSessionTimeoutMinutes: null,
        primary: null,
        me: null,
        '$clusterTime': null
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  code: undefined

Hi @Mayank_Saini,

Could you try with mongodb://localhost:27017/<database> where <database> is the name of the database you want to connect to. If you are using a different port for MongoDB, you should replace 27017 with the port number you are using.

I hope it helps! Please keep the community posted in case the issues persist.

Best regards,

Hii , sir
This solution is not working. I tried now also and earlier also . Should I share repo link .

Hi @Mayank_Saini,

The error indicates that the connection to has been closed, and the application is not able connect with your MongoDB server.

  • Could you please confirm that your MongoDB server is running and accessible. You can do this by running mongod in your terminal or command prompt.
  • Also, make sure that your MongoDB server’s configuration file (mongod.conf) is properly configured to accept connections from your application.

I hope it helps!

Best regards,

Hii sir ,
Terminal commands also not working.

I am sending GitHub repo link also for better understanding GitHub - Mayanks08/Backend-codes: my backend learning
with code image .

Hi @Mayank_Saini,

I see you shared a screenshot of an error message. While screenshots are great, but we always encourage users to share the code and error message in a textual format for better visibility and searchability.

However, looking at the screenshot you shared, the error message indicates that you need to install MongoDB on your local machine. You can refer to the MongoDB documentation to install MongoDB locally.

Rather, if you’d prefer a quicker option, you can also spin up a free M0 tier MongoDB Atlas cluster. This way, you can get started right away using the SRV connection string in your application.

I hope it helps! Feel free to reach out in case you need any further assistance.