Reputation: 1278
When connecting to a mongodb instance using golang we can either specify the value for maxPoolSize
via the connection string or using ClientOptions.SetMaxPoolSize
from the mongo-driver
package.
This means a code snippet initializing a connection could look something like this:
opts := options.Client().ApplyURI(mongodb://foor:bar@localhost:27017/test?maxPoolSize=123)
opts.SetMaxPoolSize(234)
client, err := mongo.NewClient(opts)
Given the above, my question is which one of the maxPoolSize
specifications takes precedent, is it the one in the connection string or the one specified via the driver?
Upvotes: 1
Views: 758
Reputation: 1278
With the help of the hint from D. SM I was able to find where this is specified in the docs. The precedence rules for mongo-driver
can be found in the godoc for the function ClientOptions.ApplyURI
:
If the connection string contains any options that have previously been set, it will overwrite them. Options that correspond to multiple URI parameters, such as WriteConcern, will be completely overwritten if any of the query parameters are specified. If an option is set on ClientOptions after this method is called, that option will override any option applied via the connection string.
Meaning that whatever was specified last takes precedent. So in the above case the maxPoolSize
set via the driver would be the one used by the client.
Upvotes: 1