I am currently facing an issue with connecting to a larger database through node. In the past, I have successfully connected to smaller databases using a Mongo URL in this format:
mongodb://[username]:[password]@db1-a0.example.net:27017/[DB-Name]
However, when attempting to connect to a larger DB using the following Mongo URL:
mongodb://[username]:[password]@db1-a1.example.net:27017,db2.example.net:2500/[DB-Name]?replicaSet=test
An error ' RangeError: Maximum call stack size exceeded' occurs and prevents the connection from being established. The only difference between the two URLs is the database size.
I have verified the database details and confirmed access through RoboMongo / Robo 3T, indicating that the database does indeed exist.
The attempt to establish a connection is made using Mongoose version ^5.2.10 along with the provided code:
function connect() {
if (MONGO_URL) {
mongoose.connect(MONGO_URL, err => {
if (err) {
console.log('error connecting')
console.log(err)
}
})
} else {
mongoose.connect(`mongodb://${host}`, {
user,
pass,
dbName,
useNewUrlParser: true //depresiation issue
}, err => {
if (err) {
console.log('error connecting')
console.log(err)
}
})
}
}
mongoose.connection.on('error', (message) => {
console.log('connection error!') //This is logged
console.log(message)
process.exit()
})
mongoose.connection.on('disconnected', connect)
connect()