Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61ec54b

Browse files
authored
fix(gatsby-source-mongodb): pass useUnifiedTopology option to MongoClient (gatsbyjs#21127)
* fix(gatsby-source-mongodb): pass useUnifiedTopology option to MongoClient * docs(gatsby-source-mongodb): document useUnifiedTopology as a default MongoClient option
1 parent b349d10 commit 61ec54b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/gatsby-source-mongodb/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = {
4848
properties user and password. ex. auth: { user: `admin`, password: `12345` }
4949
- **extraParams**: useful to set additional parameters for the connection, like authSource, ssl or replicaSet
5050
(needed for connecting to MongoDB Atlas db as a service), ex: extraParams: { replicaSet: `test-shard-0`, ssl: `true`, authSource: `admin` }. These are the types of options that can be appended as query parameters to the connection URI: https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options
51-
- **clientOptions**: for setting options on the creation of a `MongoClient` instance. By default to handle the various connection URI's necessary for newer versions of MongoDB Atlas, for instance, we pass { `useNewUrlParser`: `true` }. You can override the default by passing either an empty object literal or filled with other valid connection options. All options [specified in the `MongoClient` documentation](http://mongodb.github.io/node-mongodb-native/3.1/reference/connecting/connection-settings/) are valid for usage.
51+
- **clientOptions**: for setting options on the creation of a `MongoClient` instance. By default, we pass `useNewUrlParser: true` to handle the various connection URI's necessary for newer versions of MongoDB Atlas, as well as `useUnifiedTopology: true` to opt in to using the MongoDB driver's new topology engine, which improves server discovery and monitoring. You can override the default by passing either an empty object literal or filled with other valid connection options. All options [specified in the `MongoClient` documentation](http://mongodb.github.io/node-mongodb-native/3.1/reference/connecting/connection-settings/) are valid for usage.
5252
- **preserveObjectIds**: for preserving nested ObjectIDs within documents, set this to the Boolean `true`, ex: preserveObjectIds: `true`.
5353

5454
### Mapping mediatype feature

packages/gatsby-source-mongodb/src/gatsby-node.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ exports.sourceNodes = (
2222
let connectionExtraParams = getConnectionExtraParams(
2323
pluginOptions.extraParams
2424
)
25-
const clientOptions = pluginOptions.clientOptions || { useNewUrlParser: true }
25+
const clientOptions = pluginOptions.clientOptions || {
26+
useNewUrlParser: true,
27+
useUnifiedTopology: true,
28+
}
2629
const connectionURL = pluginOptions.connectionString
2730
? `${pluginOptions.connectionString}/${dbName}${connectionExtraParams}`
2831
: `mongodb://${authUrlPart}${serverOptions.address}:${serverOptions.port}/${dbName}${connectionExtraParams}`

0 commit comments

Comments
 (0)