Skip to content

Commit

Permalink
Merge pull request #9855 from Automattic/gh-9840
Browse files Browse the repository at this point in the history
Upgrade to MongoDB Driver 4.x
  • Loading branch information
vkarpov15 committed Feb 9, 2021
2 parents 0089566 + a8550dd commit f3fee5e
Show file tree
Hide file tree
Showing 51 changed files with 373 additions and 959 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
node: [10, 12, 14, 15]
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
sudo: false
node_js: [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4]
node_js: [15, 14, 12, 10]
install:
- travis_retry npm install
before_script:
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ Both `connect` and `createConnection` take a `mongodb://` URI, or the parameters

```js
await mongoose.connect('mongodb://localhost/my_database', {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
});
Expand Down
9 changes: 0 additions & 9 deletions docs/connections.pug
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,6 @@ block content
The following options are important for tuning Mongoose only if you are
running **without** [the `useUnifiedTopology` option](/docs/deprecations.html#useunifiedtopology):

* `autoReconnect` - The underlying MongoDB driver will automatically try to reconnect when it loses connection to MongoDB. Unless you are an extremely advanced user that wants to manage their own connection pool, do **not** set this option to `false`.
* `reconnectTries` - If you're connected to a single server or mongos proxy (as opposed to a replica set), the MongoDB driver will try to reconnect every `reconnectInterval` milliseconds for `reconnectTries` times, and give up afterward. When the driver gives up, the mongoose connection emits a `reconnectFailed` event. This option does nothing for replica set connections.
* `reconnectInterval` - See `reconnectTries`
* `bufferMaxEntries` - The MongoDB driver also has its own buffering mechanism that kicks in when the driver is disconnected. Set this option to 0 and set `bufferCommands` to `false` on your schemas if you want your database operations to fail immediately when the driver is not connected, as opposed to waiting for reconnection.
* `connectTimeoutMS` - How long the MongoDB driver will wait before killing a socket due to inactivity _during initial connection_. Defaults to 30000. This option is passed transparently to [Node.js' `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback).

The following options are important for tuning Mongoose only if you are
running **with** [the `useUnifiedTopology` option](/docs/deprecations.html#useunifiedtopology):

* `serverSelectionTimeoutMS` - With `useUnifiedTopology`, the MongoDB driver will try to find a server to send any given operation to, and keep retrying for `serverSelectionTimeoutMS` milliseconds. If not set, the MongoDB driver defaults to using `30000` (30 seconds).
* `heartbeatFrequencyMS` - With `useUnifiedTopology`, the MongoDB driver sends a heartbeat every `heartbeatFrequencyMS` to check on the status of the connection. A heartbeat is subject to `serverSelectionTimeoutMS`, so the MongoDB driver will retry failed heartbeats for up to 30 seconds by default. Mongoose only emits a `'disconnected'` event after a heartbeat has failed, so you may want to decrease this setting to reduce the time between when your server goes down and when Mongoose emits `'disconnected'`. We recommend you do **not** set this setting below 1000, too many heartbeats can lead to performance degradation.

Expand Down
2 changes: 1 addition & 1 deletion docs/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ block content
```javascript
// getting-started.js
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', {useNewUrlParser: true, useUnifiedTopology: true});
mongoose.connect('mongodb://localhost/test');
```

We have a pending connection to the test database running on localhost.
Expand Down
2 changes: 1 addition & 1 deletion docs/lambda.pug
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ block content
// disconnected from MongoDB and send them when it reconnects.
// With serverless, better to fail fast if not connected.
bufferCommands: false, // Disable mongoose buffering
bufferMaxEntries: 0 // and MongoDB driver buffering
serverSelectionTimeoutMS: 5000
});

// `await`ing connection after assigning to the `conn` variable
Expand Down
2 changes: 1 addition & 1 deletion docs/models.pug
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ block content
uses is open. Every model has an associated connection. When you use
`mongoose.model()`, your model will use the default mongoose connection.
```javascript
mongoose.connect('mongodb://localhost/gettingstarted', {useNewUrlParser: true});
mongoose.connect('mongodb://localhost/gettingstarted');
```
:markdown
If you create a custom connection, use that connection's `model()` function
Expand Down
2 changes: 1 addition & 1 deletion docs/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ for (const filename of files) {
run().catch(error => console.error(error.stack));

async function run() {
await mongoose.connect(config.uri, { useNewUrlParser: true, dbName: 'mongoose' });
await mongoose.connect(config.uri, { dbName: 'mongoose' });

await Content.deleteMany({});
for (const content of contents) {
Expand Down
2 changes: 0 additions & 2 deletions docs/tutorials/ssl.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ server is not registered with an established certificate authority. The solution

```javascript
await mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true,
ssl: true,
sslValidate: true,
// For example, see https://medium.com/@rajanmaharjan/secure-your-mongodb-connections-ssl-tls-92e2addb3c89
Expand Down
4 changes: 1 addition & 3 deletions examples/redis-todo/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/redis-todo',
{ useNewUrlParser: true, useCreateIndex: true }
);
mongoose.connect('mongodb://localhost/redis-todo');
Loading

0 comments on commit f3fee5e

Please sign in to comment.