Skip to content

Commit

Permalink
Merge pull request #13001 from hasezoey/useBLC
Browse files Browse the repository at this point in the history
Update broken & outdated links
  • Loading branch information
vkarpov15 committed Feb 6, 2023
2 parents 63a56eb + b3d94a3 commit 4e18a07
Show file tree
Hide file tree
Showing 66 changed files with 681 additions and 634 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Mongoose 6.0.0 was released on August 24, 2021. You can find more details on [ba
- [Bug Reports](https://github.com/Automattic/mongoose/issues/)
- [Mongoose Slack Channel](http://slack.mongoosejs.io/)
- [Help Forum](http://groups.google.com/group/mongoose-orm)
- [MongoDB Support](https://docs.mongodb.org/manual/support/)
- [MongoDB Support](https://www.mongodb.com/docs/manual/support/)

## Plugins

Expand Down
4 changes: 2 additions & 2 deletions docs/change-streams.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Change Streams

[Change streams](https://www.mongodb.com/developer/quickstart/nodejs-change-streams-triggers/) let you listen for updates to documents in a given model's collection, or even documents in an entire database.
[Change streams](https://www.mongodb.com/developer/languages/javascript/nodejs-change-streams-triggers/) let you listen for updates to documents in a given model's collection, or even documents in an entire database.
Unlike [middleware](middleware.html), change streams are a MongoDB server construct, which means they pick up changes from anywhere.
Even if you update a document from a MongoDB GUI, your Mongoose change stream will be notified.

Expand Down Expand Up @@ -81,4 +81,4 @@ exports.handler = async (event, context) => {
resumeAfter = changeStream.resumeToken;
await changeStream.close();
};
```
```
2 changes: 1 addition & 1 deletion docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</style>

Mongoose relies on the [MongoDB Node.js Driver](http://mongodb.github.io/node-mongodb-native/) to talk to MongoDB.
You can refer to [this table](https://docs.mongodb.com/drivers/node/current/compatibility/) for up-to-date information as to which version of the MongoDB driver supports which version of MongoDB.
You can refer to [this table](https://www.mongodb.com/docs/drivers/node/current/compatibility/) for up-to-date information as to which version of the MongoDB driver supports which version of MongoDB.

Below are the [semver](http://semver.org/) ranges representing which versions of mongoose are compatible with the listed versions of MongoDB server.

Expand Down
18 changes: 9 additions & 9 deletions docs/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can also specify several more parameters in the `uri`:
mongoose.connect('mongodb://username:password@host:port/database?options...');
```

See the [mongodb connection string spec](http://docs.mongodb.org/manual/reference/connection-string/) for more details.
See the [mongodb connection string spec](http://www.mongodb.com/docs/manual/reference/connection-string/) for more details.

<ul class="toc">
<li><a href="#buffering">Buffering</a></li>
Expand Down Expand Up @@ -146,11 +146,11 @@ exceptions that are explained below.
Below are some of the options that are important for tuning Mongoose.

* `promiseLibrary` - Sets the [underlying driver's promise library](http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
* `maxPoolSize` - The maximum number of sockets the MongoDB driver will keep open for this connection. By default, `maxPoolSize` is 100. Keep in mind that MongoDB only allows one operation per socket at a time, so you may want to increase this if you find you have a few slow queries that are blocking faster queries from proceeding. See [Slow Trains in MongoDB and Node.js](http://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs). You may want to decrease `maxPoolSize` if you are running into [connection limits](https://docs.atlas.mongodb.com/reference/atlas-limits/#connection-limits-and-cluster-tier).
* `maxPoolSize` - The maximum number of sockets the MongoDB driver will keep open for this connection. By default, `maxPoolSize` is 100. Keep in mind that MongoDB only allows one operation per socket at a time, so you may want to increase this if you find you have a few slow queries that are blocking faster queries from proceeding. See [Slow Trains in MongoDB and Node.js](http://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs). You may want to decrease `maxPoolSize` if you are running into [connection limits](https://www.mongodb.com/docs/atlas/atlas-limits/#connection-limits-and-cluster-tier).
* `minPoolSize` - The minimum number of sockets the MongoDB driver will keep open for this connection. The MongoDB driver may close sockets that have been inactive for some time. You may want to increase `minPoolSize` if you expect your app to go through long idle times and want to make sure your sockets stay open to avoid slow trains when activity picks up.
* `socketTimeoutMS` - How long the MongoDB driver will wait before killing a socket due to inactivity _after initial connection_. A socket may be inactive because of either no activity or a long-running operation. This is set to `30000` by default, you should set this to 2-3x your longest running operation if you expect some of your database operations to run longer than 20 seconds. This option is passed to [Node.js `socket#setTimeout()` function](https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback) after the MongoDB driver successfully completes.
* `family` - Whether to connect using IPv4 or IPv6. This option passed to [Node.js' `dns.lookup()`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) function. If you don't specify this option, the MongoDB driver will try IPv6 first and then IPv4 if IPv6 fails. If your `mongoose.connect(uri)` call takes a long time, try `mongoose.connect(uri, { family: 4 })`
* `authSource` - The database to use when authenticating with `user` and `pass`. In MongoDB, [users are scoped to a database](https://docs.mongodb.com/manual/tutorial/manage-users-and-roles/). If you are getting an unexpected login failure, you may need to set this option.
* `authSource` - The database to use when authenticating with `user` and `pass`. In MongoDB, [users are scoped to a database](https://www.mongodb.com/docs/manual/tutorial/manage-users-and-roles/). If you are getting an unexpected login failure, you may need to set this option.
* `serverSelectionTimeoutMS` - 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` - 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 Expand Up @@ -218,11 +218,11 @@ or `ssl`, in the connection string, and options that should remain constant,
like `connectTimeoutMS` or `maxPoolSize`, in the options object.

The MongoDB docs have a full list of
[supported connection string options](https://docs.mongodb.com/manual/reference/connection-string/).
[supported connection string options](https://www.mongodb.com/docs/manual/reference/connection-string/).
Below are some options that are often useful to set in the connection string because they
are closely associated with the hostname and authentication information.

* `authSource` - The database to use when authenticating with `user` and `pass`. In MongoDB, [users are scoped to a database](https://docs.mongodb.com/manual/tutorial/manage-users-and-roles/). If you are getting an unexpected login failure, you may need to set this option.
* `authSource` - The database to use when authenticating with `user` and `pass`. In MongoDB, [users are scoped to a database](https://www.mongodb.com/docs/manual/tutorial/manage-users-and-roles/). If you are getting an unexpected login failure, you may need to set this option.
* `family` - Whether to connect using IPv4 or IPv6. This option passed to [Node.js' `dns.lookup()`](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback) function. If you don't specify this option, the MongoDB driver will try IPv6 first and then IPv4 if IPv6 fails. If your `mongoose.connect(uri)` call takes a long time, try `mongoose.connect(uri, { family: 4 })`

<h3 id="connection-events"><a href="#connection-events">Connection Events</a></h3>
Expand All @@ -239,7 +239,7 @@ connection may emit.
* `disconnected`: Emitted when Mongoose lost connection to the MongoDB server. This event may be due to your code explicitly closing the connection, the database server crashing, or network connectivity issues.
* `close`: Emitted after [`Connection#close()`](api/connection.html#connection_Connection-close) successfully closes the connection. If you call `conn.close()`, you'll get both a 'disconnected' event and a 'close' event.
* `reconnected`: Emitted if Mongoose lost connectivity to MongoDB and successfully reconnected. Mongoose attempts to [automatically reconnect](https://thecodebarbarian.com/managing-connections-with-the-mongodb-node-driver.html) when it loses connection to the database.
* `error`: Emitted if an error occurs on a connection, like a `parseError` due to malformed data or a payload larger than [16MB](https://docs.mongodb.com/manual/reference/limits/#BSON-Document-Size).
* `error`: Emitted if an error occurs on a connection, like a `parseError` due to malformed data or a payload larger than [16MB](https://www.mongodb.com/docs/manual/reference/limits/#BSON-Document-Size).
* `fullsetup`: Emitted when you're connecting to a replica set and Mongoose has successfully connected to the primary and at least one secondary.
* `all`: Emitted when you're connecting to a replica set and Mongoose has successfully connected to all servers specified in your connection string.

Expand Down Expand Up @@ -332,8 +332,8 @@ This can cause confusing errors if you're connecting to a remote MongoDB replica
MongooseServerSelectionError: connect ECONNREFUSED localhost:27017
```

If you're experiencing a similar error, connect to the replica set using the `mongo` shell and run the [`rs.conf()`](https://docs.mongodb.com/manual/reference/method/rs.conf/) command to check the host names of each replica set member.
Follow [this page's instructions to change a replica set member's host name](https://docs.mongodb.com/manual/tutorial/change-hostnames-in-a-replica-set/#change-hostnames-while-maintaining-replica-set-availability).
If you're experiencing a similar error, connect to the replica set using the `mongo` shell and run the [`rs.conf()`](https://www.mongodb.com/docs/manual/reference/method/rs.conf/) command to check the host names of each replica set member.
Follow [this page's instructions to change a replica set member's host name](https://www.mongodb.com/docs/manual/tutorial/change-hostnames-in-a-replica-set/#change-hostnames-while-maintaining-replica-set-availability).

You can also check the `reason.servers` property of `MongooseServerSelectionError` to see what the MongoDB Node driver thinks the state of your replica set is.
The `reason.servers` property contains a [map](https://masteringjs.io/tutorials/fundamentals/map) of server descriptions.
Expand All @@ -354,7 +354,7 @@ if (err.name === 'MongooseServerSelectionError') {

<h3 id="mongos_connections"><a href="#mongos_connections">Multi-mongos support</a></h3>

You can also connect to multiple [mongos](https://docs.mongodb.com/manual/reference/program/mongos/) instances
You can also connect to multiple [mongos](https://www.mongodb.com/docs/manual/reference/program/mongos/) instances
for high availability in a sharded cluster. You do
[not need to pass any special options to connect to multiple mongos](http://mongodb.github.io/node-mongodb-native/3.0/tutorials/connect/#connect-to-sharded-cluster) in mongoose 5.x.

Expand Down
2 changes: 1 addition & 1 deletion docs/defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ execute that function and use the return value as the default.

### The `setDefaultsOnInsert` Option

Mongoose also sets defaults on `update()` and `findOneAndUpdate()` when the `upsert` option is set by adding your schema's defaults to a [MongoDB `$setOnInsert` operator](https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/).
Mongoose also sets defaults on `update()` and `findOneAndUpdate()` when the `upsert` option is set by adding your schema's defaults to a [MongoDB `$setOnInsert` operator](https://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/).
You can disable this behavior by setting the `setDefaultsOnInsert` option to `false`.

```javascript
Expand Down
8 changes: 4 additions & 4 deletions docs/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ deleteMany, or bulkWrite instead.
```

To remove this deprecation warning, replace any usage of `remove()` with
`deleteMany()`, _unless_ you specify the [`single` option to `remove()`](model.html#model_Model-remove). The `single`
`deleteMany()`, _unless_ you specify the [`single` option to `remove()`](api/model.html#model_Model-remove). The `single`
option limited `remove()` to deleting at most one document, so you should
replace `remove(filter, { single: true })` with `deleteOne(filter)`.

Expand All @@ -46,9 +46,9 @@ MyModel.deleteOne({ answer: 42 });

<h2 id="update"><a href="#update"><code>update()</code></a></h2>

Like `remove()`, the [`update()` function](model.html#model_Model-update) is deprecated in favor
of the more explicit [`updateOne()`](model.html#model_Model-updateOne), [`updateMany()`](model.html#model_Model-updateMany), and [`replaceOne()`](model.html#model_Model-replaceOne) functions. You should replace
`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](model.html#model_Model-update).
Like `remove()`, the [`update()` function](api/model.html#model_Model-update) is deprecated in favor
of the more explicit [`updateOne()`](api/model.html#model_Model-updateOne), [`updateMany()`](api/model.html#model_Model-updateMany), and [`replaceOne()`](api/model.html#model_Model-replaceOne) functions. You should replace
`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](api/model.html#model_Model-update).

```
collection.update is deprecated. Use updateOne, updateMany, or bulkWrite
Expand Down
4 changes: 2 additions & 2 deletions docs/documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ doc instanceof mongoose.Document; // true
<h2 id="updating-using-save"><a href="#updating-using-save">Updating Using <code>save()</code></a></h2>

Mongoose documents track changes. You can modify a document using vanilla
JavaScript assignments and Mongoose will convert it into [MongoDB update operators](https://docs.mongodb.com/manual/reference/operator/update/).
JavaScript assignments and Mongoose will convert it into [MongoDB update operators](https://www.mongodb.com/docs/manual/reference/operator/update/).

```javascript
doc.name = 'foo';
Expand Down Expand Up @@ -88,7 +88,7 @@ way to update a document with Mongoose. With `save()`, you get full
[validation](validation.html) and [middleware](middleware.html).

For cases when `save()` isn't flexible enough, Mongoose lets you create
your own [MongoDB updates](https://docs.mongodb.com/manual/reference/operator/update/)
your own [MongoDB updates](https://www.mongodb.com/docs/manual/reference/operator/update/)
with casting, [middleware](middleware.html#notes), and [limited validation](validation.html#update-validators).

```javascript
Expand Down
8 changes: 4 additions & 4 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ await Test.findOne(); // Will throw "Operation timed out" error because `db` isn

<a class="anchor" href="#not-local"> **Q**</a>. I am able to connect locally but when I try to connect to MongoDB Atlas I get this error. What gives?

You must ensure that you have whitelisted your ip on [mongodb](https://docs.atlas.mongodb.com/security/ip-access-list/) to allow Mongoose to connect.
You must ensure that you have whitelisted your ip on [mongodb](https://www.mongodb.com/docs/atlas/security/ip-access-list/) to allow Mongoose to connect.
You can allow access from all ips with `0.0.0.0/0`.

<hr id="not-a-function" />
Expand All @@ -55,7 +55,7 @@ If you're storing schemas or models in a separate npm package, please list Mongo
<a class="anchor" href="#unique-doesnt-work">**Q**</a>. I declared a schema property as `unique` but I can still save duplicates. What gives?

**A**. Mongoose doesn't handle `unique` on its own: `{ name: { type: String, unique: true } }`
is just a shorthand for creating a [MongoDB unique index on `name`](https://docs.mongodb.com/manual/core/index-unique/).
is just a shorthand for creating a [MongoDB unique index on `name`](https://www.mongodb.com/docs/manual/core/index-unique/).
For example, if MongoDB doesn't already have a unique index on `name`, the below code will not error despite the fact that `unique` is true.

```javascript
Expand Down Expand Up @@ -96,7 +96,7 @@ Model.init().then(function() {

MongoDB persists indexes, so you only need to rebuild indexes if you're starting
with a fresh database or you ran `db.dropDatabase()`. In a production environment,
you should [create your indexes using the MongoDB shell](https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/)
you should [create your indexes using the MongoDB shell](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndex/)
rather than relying on mongoose to do it for you. The `unique` option for schemas is
convenient for development and documentation, but mongoose is *not* an index management solution.

Expand Down Expand Up @@ -381,7 +381,7 @@ validating, and then subsequently invalidating the same path.

<a class="anchor" href="#objectid-validation">**Q**</a>. Why is **any** 12 character string successfully cast to an ObjectId?

**A**. Technically, any 12 character string is a valid [ObjectId](https://docs.mongodb.com/manual/reference/bson-types/#objectid).
**A**. Technically, any 12 character string is a valid [ObjectId](https://www.mongodb.com/docs/manual/reference/bson-types/#objectid).
Consider using a regex like `/^[a-f0-9]{24}$/` to test whether a string is exactly 24 hex characters.

<hr id="map-keys-strings" />
Expand Down
10 changes: 5 additions & 5 deletions docs/geojson.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ that the MongoDB driver does. For example, the below script saves a
`city` document those `location` property is a GeoJSON point representing
the city of Denver, Colorado. It then queries for all documents within
a polygon representing the state of Colorado using
[the MongoDB `$geoWithin` operator](https://docs.mongodb.com/manual/reference/operator/query/geoWithin/).
[the MongoDB `$geoWithin` operator](https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/).

<img src="https://i.imgur.com/i32pWnC.png">

```javascript
[require:geojson.*driver query]
```

Mongoose also has a [`within()` helper](query.html#query_Query-within)
Mongoose also has a [`within()` helper](api/query.html#query_Query-within)
that's a shorthand for `$geoWithin`.

```javascript
Expand All @@ -136,7 +136,7 @@ that's a shorthand for `$geoWithin`.

<h2 id="geospatial-indexes">Geospatial Indexes</h2>

MongoDB supports [2dsphere indexes](https://docs.mongodb.com/manual/core/2dsphere/)
MongoDB supports [2dsphere indexes](https://www.mongodb.com/docs/manual/core/2dsphere/)
for speeding up geospatial queries. Here's how you can define
a 2dsphere index on a GeoJSON point:

Expand All @@ -151,6 +151,6 @@ as shown below.
citySchema.index({ location: '2dsphere' });
```

MongoDB's [`$near` query operator](https://docs.mongodb.com/v4.0/reference/operator/query/near/#op._S_near)
and [`$geoNear` aggregation stage](https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/#pipe._S_geoNear)
MongoDB's [`$near` query operator](https://www.mongodb.com/docs/manual/reference/operator/query/near/)
and [`$geoNear` aggregation stage](https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#pipe._S_geoNear)
_require_ a 2dsphere index.
Loading

0 comments on commit 4e18a07

Please sign in to comment.