Mongoose unable to connect with Mongo Standalone replicaSet

Detail about the issue.

I have converted my MongoDB instance to a standalone ReplicaSet using the following config.

  destination: file   
  path: /opt/homebrew/var/log/mongodb/mongo.log  
  logAppend: true  
  dbPath: /opt/homebrew/var/mongodb  
  replSetName: "rs0"  
    authorization: "enabled"  
    keyFile: /Users/username/mongodb.key   

Using the following Mongo URI to connect to my MongoDB instance


using the URI I can connect to my MongoDB through Studio3T but when I use this URI in my Node app through Mongoose it never connects, nor gives any error.

Following are the Screenshots for rs.status() output displaying details of member
member data from rs.status

Additional details.
NodeJs version: v14.19.1
Mongoose version: 6.3.2
MongoDB version: 5.0.7

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() {
  let opt = {poolSize:1, useNewUrlParser: true, useUnifiedTopology: true}
  let conn = await MongoClient.connect(
  console.log('db connected')
  console.log(await conn.db('test').collection('test').findOne())
  console.log('db closed')

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

1 Like

A post was split to a new topic: Having a problem when trying to connect to replica set with compass and with python code