Reputation: 11
My application runs on NodeJS 4.4.7 and uses MongoDB driver 2.2.31 (not Mongoose) to connect to Azure CosmosDB. This is how I connect to the DB:
var connectionString = 'mongodb://USERNAME:[email protected]:10255/DB_NAME?ssl=true'
var options = {
db: { j: false },
server: { autoReconnect: true, socketOptions: { connectTimeoutMS: 300000 } },
};
require('mongodb').MongoClient.connect(connectionString, options, callback);
And I recently started experiencing the following error:
MongoError: connection X to http://yyy.documents.azure.com:10255 timed out
where X is a small integer (I've seen 8, 10, 29, and so on).
Some background info:
&replicaSet=globaldb
)I'm not sure if it is a temporary issue from Azure or there is something wrong in the way I connect to CosmosDB. Any suggestion would be appreciated!
Upvotes: 1
Views: 3866
Reputation: 321
This issue might be related to not setting client-side connection parameters properly. Could you please try to set these and see if it resolves the timeout issue?
MongoClientOptions.Builder optionsBuilder = new MongoClientOptions.Builder();
optionsBuilder.socketTimeout(10000);
optionsBuilder.maxConnectionIdleTime(60000);
optionsBuilder.heartbeatConnectTimeout(5000);
MongoClientURI mongoClientURI = new MongoClientURI(props.getMongoDbConnection(), optionsBuilder);
Upvotes: 1