2

I am trying to fetch data from MongoDB, where database connection is ok everytime, there isn't any error. But when I am trying to fetch data it gives me the error below:

 { [MongoError: connection 5 to c1669.candidate.18.mongolayer.com:11669 timed out]
   name: 'MongoError',
   message: 'connection 5 to c1669.candidate.18.mongolayer.com:11669 timed out' }

But first 10 to 11 attempts were good and was getting expected data from mongo, later I introduced by above error continuously.

For more info: Using mongodb npm module.

3
  • Can you show us the code that you are trying? Commented Sep 26, 2016 at 12:38
  • Sorry! I can't show my code segment. I am bound with an agreement. Commented Sep 26, 2016 at 14:04
  • Now, sometime getting error of "no primary found in replicaset". And mostly prior error with the only change of 7 instead of 5 ie. { [MongoError: connection 7 to c1669.candidate.18.mongolayer.com:11669 timed out] name: 'MongoError', message: 'connection 7 to c1669.candidate.18.mongolayer.com:11669 timed out' } Commented Sep 26, 2016 at 14:16

2 Answers 2

1

I think its connection pool size problem as you are saying first 10-11 attempts are good so may be you have defined very limited pool size for connections so when you are creating connections, after exceeding to limit it is not allowing to query the database. Please check it as I am not sure without seeing the code but this might be the reason.

Update:

Try below options at the time of connecting to db.

var dbOptions = {
    server: {
        socketOptions: {
            keepAlive: 100,
            connectTimeoutMS: 30000
        }
    }
};

mongoose.connect('mongodb://localhost/db', dbOptions);

Please refer to this link as it seems that you are using replicaset. https://github.com/Automattic/mongoose/issues/2089

Sign up to request clarification or add additional context in comments.

2 Comments

Now I am using: var options = {native_parser: true, poolSize:50, server: {socketOptions: {connectTimeoutMS: 15000, socketTimeoutMS: 15000}}}; Still facing same error. Anything else?
Can anyone help? It's like nightmare for me.
0

Please update to mongodb driver 2.2.10+ version - because there were some minor issues with connection-pool refactoring between 2.1.11–2.2.4 versions.

See

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.