Skip to content

Commit

Permalink
docs(connection): improve connection string query param docs
Browse files Browse the repository at this point in the history
Fix #5864
  • Loading branch information
vkarpov15 committed Dec 6, 2017
1 parent a11c05e commit 83d9a98
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions docs/connections.jade
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,24 @@ block content

h4#connection-string-options Connection String Options
:markdown
Mongoose supports the following options in the connection string.

* [ssl](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
* [poolSize](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
* [autoReconnect](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
* [socketTimeoutMS](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
* [connectTimeoutMS](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
* [authSource](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
* [retries](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
* [authMechanism](http://mongodb.github.io/node-mongodb-native/2.2/tutorials/connect/authenticating/)
* [reconnectWait](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
* [rs_name](http://mongodb.github.io/node-mongodb-native/2.1/api/ReplSet.html)
* [replicaSet](http://mongodb.github.io/node-mongodb-native/2.1/api/ReplSet.html)
* [nativeParser](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
* [w](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
* [journal](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
* [wtimeoutMS](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
* [readPreference](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
* [readPreferenceTags](http://mongodb.github.io/node-mongodb-native/2.1/api/Db.html)
* [sslValidate](http://mongodb.github.io/node-mongodb-native/2.1/api/Server.html)
You can also specify options in your connection string as [parameters in the query string](https://en.wikipedia.org/wiki/Query_string) portion of the URI.
:js
mongoose.connect('mongodb://localhost:27017/test?connectTimeoutMS=1000', { useMongoClient: true });
// The above is equivalent to:
mongoose.connect('mongodb://localhost:27017/test', {
useMongoClient: true,
connectTimeoutMS: 1000
});
:markdown
The disadvantage of putting options in the query string is that query
string options are harder to read. The advantage is that you only need a
single configuration option, the URI, rather than separate options for
`socketTimeoutMS`, `connectTimeoutMS`, etc. Best practice is to put options
that likely differ between development and production, like `replicaSet`
or `ssl`, in the connection string, and options that should remain constant,
like `connectTimeoutMS` or `poolSize`, in the options object.

The MongoDB docs have a full list of [supported connection string options](https://docs.mongodb.com/manual/reference/connection-string/)

h4#keepAlive A note about keepAlive
.important
Expand Down

0 comments on commit 83d9a98

Please sign in to comment.