Closed amit777 closed 7 years ago
everything seems to work if I do not set "mongos: true"
Is there any gotcha regarding topologies or reconnection logic that I missing?
Try setting mongos: { socketOptions: { /* ... */ }
instead of mongos: true
. The mongos: true
hack is for people who don't want to set any mongos options.
Got it! thanks. Out of curiousity, are there any behavioral differences in the mongo client if it's connecting to a mongos vs a regular mongod?
"Behavioral differences" is pretty vague. As far as mongoose is concerned, the only difference between sharded and not sharded is the built-in sharding plugin, which prevents you from changing a document's shard key values if you set the shardKey
option. That's the only sharding-specific functionality mongoose offers, modulo any community plugins you might add.
sorry to re-open. I think the example configuration in the documentation at http://mongoosejs.com/docs/connections.html is a bit misleading:
var options = {
db: { native_parser: true },
server: { poolSize: 5 },
replset: { rs_name: 'myReplicaSetName' },
user: 'myUserName',
pass: 'myPassword'
}
The poolSize parameter is set on the server attribute rather than the replset attribute. Is my understanding correct that you should use only 1 of the following attributes: 'server', 'replset', 'mongos'. Or is it appropriate to have some configurations under 'server' and other configs under 'replset' etc? I can create a pull request for the documentation if it's better to have 3 different example configs depending on your mongo environment.
It's somewhat confusing but there are cases when you want to use all of these attributes, because if you're connecting to a sharded cluster you're connecting to one or more replica sets, and in turn to individual servers. poolSize
is configured on the individual server
level regardless of whether you're connecting to a standalone, a replica set, or a sharded cluster.
for latest version of mongodb, I think settings should be:
mongoose.connect(
mongodb://${username}:${password}@ds016000-a0.mlab.com:16000,ds016000-a1.mlab.com:16084/azure_rn_paid?replicaSet=rs-ds016000
,
{
useNewUrlParser: true,
auto_reconnect: true,
connectTimeoutMS: 3600000,
keepAlive: 3600000,
socketTimeoutMS: 3600000
}
);
Do you want to request a feature or report a bug? bug
What is the current behavior? when using mongos in sharded cluster configuration, socketOptions are not passed to underlying drivers correctly
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
socketTimeout (or socketTimeoutMS or connectionTimeout or connectionTimeoutMS) should be set in mongos: true is set in dbOptions
as a side note, all the namings of the various timeout options are very confusing and seem inconsistent. I've tried all kinds of combinations and it would be good to know what the recommended setting names are.
Please mention your node.js, mongoose and MongoDB version. node 7.9.0, mongoose 4.10.2, mongodb 3.4.4