Mongoose unable to connect with Mongo Standalone replicaSet

Hi @Shivam_Spraxa

It’s been a while since you posted this question. Are you still having issues with connecting using Mongoose?

If yes, what if you try to connect using a simple node script, e.g:

const MongoClient = require('mongodb').MongoClient;

let run = async function() {
  console.log('start')
  let opt = {poolSize:1, useNewUrlParser: true, useUnifiedTopology: true}
  let conn = await MongoClient.connect(
    'mongodb://username:password@127.0.0.1:27017/test?authSource=admin&replicaSet=rs0',
    opt)
  console.log('db connected')
  console.log(await conn.db('test').collection('test').findOne())
  conn.close()
  console.log('db closed')
}().catch(console.error)

The snippet above should try to connect to the database test, then print a single document from the collection test. If this snippet works, then we need to look deeper into why Mongoose have issues.

Best regards
Kevin

1 Like