0

I'm having issues connecting to my local MongoDB. On connection, it fails with the following error message:

MongooseServerSelectionError: connection timed out
reason: TopologyDescription {
    type: 'Single',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map { 'localhost:27017' => [ServerDescription] },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: null
  }

Setup is pretty basic:

const mongooseOptions = {
  useCreateIndex: true,
  useNewUrlParser: true,
  useUnifiedTopology: true,
  useFindAndModify: false,
  retryWrites: false
}
mongoose.connect("mongodb://localhost:27017/my-app", mongooseOptions).then(() => { // res
  console.log("DB Connected!")
}).catch(err => {
  console.log(`MongoDB connection error`)
  console.log(Error, err)
  process.exit(1)
})

I've seen other related posts:

  • MongoDB is on: Yes. I can connect to it in the terminal and through the Compass Atlas app. I can also see it in my Activity Monitor
  • IP restrictions: There are none, it's local. I don't need to update the settings in MongoDB atlas website
  • Docker: I'm not using Docker. Just MongoDB installed through brew. It's been working for years, just started failing since I switched to typescript.

Any help is much appreciated. Here attached are the mongologs: enter image description here

Maybe useful info:

  • I tried to connect with a Mongo Atlas URI (so not localhost), and it works.
  • I recently updated to Typescript on the server. When I run the code not using ts-node but the built version, it works. I'm wondering if it's not something to do with ts-node.
denislexic
  • 10,786
  • 23
  • 84
  • 128

0 Answers0