Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Error: while run server..Connection Failed

Hi,

below the code of my package.json file.

{

  "name": "mean-course",

  "version": "0.0.0",

  "scripts": {

    "ng": "ng",

    "start": "ng serve",

    "build": "ng build",

    "test": "ng test",

    "lint": "ng lint",

    "e2e": "ng e2e",

    "serve": "nodemon server.js"

  },

When i start to run server using Commond : npm run serve

then server started and then failed like below this.

[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
MongooseServerSelectionError: bad auth Authentication failed.
    at NativeConnection.Connection.openUri (D:\twt\mean-cource\mean-course\node_modules\mongoose\lib\connection.js:826:32)
    at Mongoose.connect (D:\twt\mean-cource\mean-course\node_modules\mongoose\lib\index.js:335:15)
    at Object.<anonymous> (D:\twt\mean-cource\mean-course\backend\app.js:21:10)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (D:\twt\mean-cource\mean-course\server.js:1:13)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map {
      'cluster0-shard-00-01-scb3m.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-02-scb3m.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-00-scb3m.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: null
  }
}
Connection Failed..

Can please help on this.

Are you able to connect to your mongodb from shell?
mongo “your_connection_string”
Check your env file for any URI issues

yes, but after connected, its failed in a 5 second something

So your connection from shell failed in few seconds?
With what error

Did you try npx serve

I tried but and everything done in my App, but due to this i stuck, its not showing error.
just showing after few second like Connection Faild.
Please help on this.

[nodemon] restarting due to changes…
[nodemon] starting node server.js
Connection Failed…

Where are you running mongodb? locally, on your computer, or remotely, like on Atlas or a server somewhere?