Skip to content

Commit 9572cbd

Browse files
authored
Merge pull request #14808 from Automattic/vkarpov15/gh-13211
docs: upgrade marked -> 14.x, use new {#id-here} syntax for declaring custom header ids
2 parents 3ee2de5 + a563adc commit 9572cbd

26 files changed

+330
-377
lines changed

benchmarks/typescript/simple/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"mongoose": "file:../../../mongoose.tgz",
4-
"typescript": "4.9.x"
4+
"typescript": "5.5.x"
55
},
66
"scripts": {
77
"benchmark": "tsc --extendedDiagnostics"

docs/async-await.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async function doStuffWithUser() {
8282
}
8383
```
8484

85-
<h2 id="queries">Async/Await with Mongoose Queries</h2>
85+
## Async/Await with Mongoose Queries {#queries}
8686

8787
Under the hood, [async/await is syntactic sugar](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await) over the Promise API.
8888
Due to the surprisingly simple way promises are implemented in JavaScript, the keyword `await` will try to unwrap any object with a property whose key is the string ‘then’ and whose value is a function.

docs/browser.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const mongoose = require('mongoose/browser');
1919
import mongoose from 'mongoose/browser';
2020
```
2121

22-
<h2 id="usage">Using the Browser Library</h2>
22+
## Using the Browser Library {#usage}
2323

2424
Mongoose's browser library is very limited. The only use case it supports is validating documents as shown below.
2525

docs/connections.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ See the [mongodb connection string spec](http://www.mongodb.com/docs/manual/refe
3535
<li><a href="#multi-tenant-connections">Multi Tenant Connections</a></li>
3636
</ul>
3737

38-
<h2 id="buffering"><a href="#buffering">Operation Buffering</a></h2>
38+
## Operation Buffering {#buffering}
3939

4040
Mongoose lets you start using your models immediately, without waiting for
4141
mongoose to establish a connection to MongoDB.
@@ -95,7 +95,7 @@ const Model = mongoose.model('Test', schema);
9595
await Model.createCollection();
9696
```
9797

98-
<h2 id="error-handling"><a href="#error-handling">Error Handling</a></h2>
98+
## Error Handling {#error-handling}
9999

100100
There are two classes of errors that can occur with a Mongoose connection.
101101

@@ -129,7 +129,7 @@ mongoose.connection.on('error', err => {
129129
Note that Mongoose does not necessarily emit an 'error' event if it loses connectivity to MongoDB. You should
130130
listen to the `disconnected` event to report when Mongoose is disconnected from MongoDB.
131131

132-
<h2 id="options"><a href="#options">Options</a></h2>
132+
## Options {#options}
133133

134134
The `connect` method also accepts an `options` object which will be passed
135135
on to the underlying MongoDB driver.
@@ -158,7 +158,7 @@ Below are some of the options that are important for tuning Mongoose.
158158
* `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).
159159
* `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.
160160

161-
<h2 id="serverselectiontimeoutms"><a href="#serverselectiontimeoutms">serverSelectionTimeoutMS</a></h2>
161+
## serverSelectionTimeoutMS {#serverselectiontimeoutms}
162162

163163
The `serverSelectionTimeoutMS` option is extremely important: it controls how long the MongoDB Node.js driver will attempt to retry any operation before erroring out.
164164
This includes initial connection, like `await mongoose.connect()`, as well as any operations that make requests to MongoDB, like `save()` or `find()`.
@@ -208,7 +208,7 @@ for (let i = 0; i < 3; ++i) {
208208
}
209209
```
210210

211-
<h2 id="callback"><a href="#callback">Callback</a></h2>
211+
## Callback {#callback}
212212

213213
The `connect()` function also accepts a callback parameter and returns a
214214
[promise](promises.html).
@@ -225,7 +225,7 @@ mongoose.connect(uri, options).then(
225225
);
226226
```
227227

228-
<h2 id="connection-string-options"><a href="#connection-string-options">Connection String Options</a></h2>
228+
## Connection String Options {#connection-string-options}
229229

230230
You can also specify driver options in your connection string as
231231
[parameters in the query string](https://en.wikipedia.org/wiki/Query_string)
@@ -258,7 +258,7 @@ are closely associated with the hostname and authentication information.
258258
* `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.
259259
* `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 })`
260260

261-
<h2 id="connection-events"><a href="#connection-events">Connection Events</a></h2>
261+
## Connection Events {#connection-events}
262262

263263
Connections inherit from [Node.js' `EventEmitter` class](https://nodejs.org/api/events.html#events_class_eventemitter),
264264
and emit events when something happens to the connection, like losing
@@ -304,13 +304,13 @@ conn.on('disconnecting', () => console.log('disconnecting'));
304304
conn.on('close', () => console.log('close'));
305305
```
306306

307-
<h2 id="keepAlive"><a href="#keepAlive">A note about keepAlive</a></h2>
307+
## A note about keepAlive {#keepAlive}
308308

309309
Before Mongoose 5.2.0, you needed to enable the `keepAlive` option to initiate [TCP keepalive](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html) to prevent `"connection closed"` errors.
310310
However, `keepAlive` has been `true` by default since Mongoose 5.2.0, and the `keepAlive` is deprecated as of Mongoose 7.2.0.
311311
Please remove `keepAlive` and `keepAliveInitialDelay` options from your Mongoose connections.
312312

313-
<h2 id="replicaset_connections"><a href="#replicaset_connections">Replica Set Connections</a></h2>
313+
## Replica Set Connections {#replicaset_connections}
314314

315315
To connect to a replica set you pass a comma delimited list of hosts to
316316
connect to rather than a single host.
@@ -331,7 +331,7 @@ To connect to a single node replica set, specify the `replicaSet` option.
331331
mongoose.connect('mongodb://host1:port1/?replicaSet=rsName');
332332
```
333333

334-
<h2 id="server-selection"><a href="#server-selection">Server Selection</a></h2>
334+
## Server Selection {#server-selection}
335335

336336
The underlying MongoDB driver uses a process known as [server selection](https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst) to connect to MongoDB and send operations to MongoDB.
337337
If the MongoDB driver can't find a server to send an operation to after `serverSelectionTimeoutMS`,
@@ -366,7 +366,7 @@ mongoose.connect(uri, {
366366
}).catch(err => console.log(err.reason));
367367
```
368368

369-
<h2 id="replicaset-hostnames"><a href="#replicaset-hostnames">Replica Set Host Names</a></h2>
369+
## Replica Set Host Names {#replicaset-hostnames}
370370

371371
MongoDB replica sets rely on being able to reliably figure out the domain name for each member.
372372
On Linux and OSX, the MongoDB server uses the output of the [`hostname` command](https://linux.die.net/man/1/hostname) to figure out the domain name to report to the replica set.
@@ -399,7 +399,7 @@ if (err.name === 'MongooseServerSelectionError') {
399399
}
400400
```
401401

402-
<h2 id="mongos_connections"><a href="#mongos_connections">Multi-mongos support</a></h2>
402+
## Multi-mongos support {#mongos_connections}
403403

404404
You can also connect to multiple [mongos](https://www.mongodb.com/docs/manual/reference/program/mongos/) instances
405405
for high availability in a sharded cluster. You do
@@ -410,7 +410,7 @@ for high availability in a sharded cluster. You do
410410
mongoose.connect('mongodb://mongosA:27501,mongosB:27501', cb);
411411
```
412412

413-
<h2 id="multiple_connections"><a href="#multiple_connections">Multiple connections</a></h2>
413+
## Multiple connections {#multiple_connections}
414414

415415
So far we've seen how to connect to MongoDB using Mongoose's default
416416
connection. Mongoose creates a *default connection* when you call `mongoose.connect()`.
@@ -493,7 +493,7 @@ module.exports = conn;
493493
You can create separate files for each connection, like `connections/web.js` and `connections/mobile.js` if you want to create separate connections for your web API backend and your mobile API backend.
494494
Your business logic can then `require()` or `import` the connection it needs.
495495

496-
<h2 id="connection_pools"><a href="#connection_pools">Connection Pools</a></h2>
496+
## Connection Pools {#connection_pools}
497497

498498
Each `connection`, whether created with `mongoose.connect` or
499499
`mongoose.createConnection` are all backed by an internal configurable
@@ -512,7 +512,7 @@ mongoose.createConnection(uri);
512512
The connection pool size is important because [MongoDB currently can only process one operation per socket](https://thecodebarbarian.com/slow-trains-in-mongodb-and-nodejs).
513513
So `maxPoolSize` functions as a cap on the number of concurrent operations.
514514

515-
<h2 id="multi-tenant-connections"><a href="#multi-tenant-connections">Multi Tenant Connections</a></h2>
515+
## Multi Tenant Connections {#multi-tenant-connections}
516516

517517
In the context of Mongoose, a multi-tenant architecture typically means a case where multiple different clients talk to MongoDB through a single Mongoose application.
518518
This typically means each client makes queries and executes updates through a single Mongoose application, but has a distinct MongoDB database within the same MongoDB cluster.
@@ -592,6 +592,6 @@ app.get('/users/:tenantId', function(req, res) {
592592
app.listen(3000);
593593
```
594594

595-
<h2 id="next">Next Up</h2>
595+
## Next Up {#next}
596596

597597
Now that we've covered connections, let's take a look at [models](models.html).

docs/deprecations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ that Mongoose users should be aware of. Mongoose provides options to work
55
around these deprecation warnings, but you need to test whether these options
66
cause any problems for your application. Please [report any issues on GitHub](https://github.com/Automattic/mongoose/issues/new).
77

8-
<h2 id="summary"><a href="#summary">Summary</a></h2>
8+
## Summary {#summary}
99

1010
To fix all deprecation warnings, follow the below steps:
1111

1212
* Replace `rawResult: true` with `includeResultMetadata: true` in `findOneAndUpdate()`, `findOneAndReplace()`, `findOneAndDelete()` calls.
1313

1414
Read below for more a more detailed description of each deprecation warning.
1515

16-
<h2 id="rawresult"><a href="#rawresult"><code>rawResult</code></a></h2>
16+
## `rawResult` {#rawresult}
1717

1818
As of Mongoose 7.4.0, the `rawResult` option to `findOneAndUpdate()` is deprecated.
1919
You should instead use the `includeResultMetadata` option, which the MongoDB Node.js driver's new option that replaces `rawResult`.

docs/documents.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ to documents as stored in MongoDB. Each document is an instance of its
1313
<li><a href="#overwriting">Overwriting</a></li>
1414
</ul>
1515

16-
<h2 id="documents-vs-models"><a href="#documents-vs-models">Documents vs Models</a></h2>
16+
## Documents vs Models {#documents-vs-models}
1717

1818
[Document](api/document.html#Document) and [Model](api/model.html#Model) are distinct
1919
classes in Mongoose. The Model class is a subclass of the Document class.
@@ -33,7 +33,7 @@ In Mongoose, a "document" generally means an instance of a model.
3333
You should not have to create an instance of the Document class without
3434
going through a model.
3535

36-
<h2 id="retrieving"><a href="#retrieving">Retrieving</a></h2>
36+
## Retrieving {#retrieving}
3737

3838
When you load documents from MongoDB using model functions like [`findOne()`](api/model.html#model_Model-findOne),
3939
you get a Mongoose document back.
@@ -46,7 +46,7 @@ doc instanceof mongoose.Model; // true
4646
doc instanceof mongoose.Document; // true
4747
```
4848

49-
<h2 id="updating-using-save"><a href="#updating-using-save">Updating Using <code>save()</code></a></h2>
49+
## Updating Using `save()` {#updating-using-save}
5050

5151
Mongoose documents track changes. You can modify a document using vanilla
5252
JavaScript assignments and Mongoose will convert it into [MongoDB update operators](https://www.mongodb.com/docs/manual/reference/operator/update/).
@@ -81,7 +81,7 @@ doc.name = 'foo';
8181
await doc.save(); // Throws DocumentNotFoundError
8282
```
8383

84-
<h2 id="updating-using-queries"><a href="#updating-using-queries">Updating Using Queries</a></h2>
84+
## Updating Using Queries {#updating-using-queries}
8585

8686
The [`save()`](api/model.html#model_Model-save) function is generally the right
8787
way to update a document with Mongoose. With `save()`, you get full
@@ -100,7 +100,7 @@ await MyModel.updateMany({}, { $set: { name: 'foo' } });
100100
execute `save()` middleware. If you need save middleware and full validation,
101101
first query for the document and then `save()` it.*
102102

103-
<h2 id="validating"><a href="#validating">Validating</a></h2>
103+
## Validating {#validating}
104104

105105
Documents are casted and validated before they are saved. Mongoose first casts
106106
values to the specified type and then validates them. Internally, Mongoose
@@ -136,7 +136,7 @@ await Person.updateOne({}, { age: -1 }, { runValidators: true });
136136

137137
Read the [validation](validation.html) guide for more details.
138138

139-
<h2 id="overwriting"><a href="#overwriting">Overwriting</a></h2>
139+
## Overwriting {#overwriting}
140140

141141
There are 2 different ways to overwrite a document (replacing all keys in the
142142
document). One way is to use the

docs/geojson.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ polygons. [MongoDB has excellent support for geospatial queries](http://thecodeb
55
on GeoJSON objects. Let's take a look at how you can use Mongoose to store
66
and query GeoJSON objects.
77

8-
<h2 id="points">Point Schema</h2>
8+
## Point Schema {#points}
99

1010
The most simple structure in GeoJSON is a point. Below is an example point
1111
representing the approximate location of [San Francisco](https://www.google.com/maps/@37.7,-122.5,9z).
@@ -64,7 +64,7 @@ const citySchema = new mongoose.Schema({
6464
});
6565
```
6666

67-
<h2 id="polygons">Polygon Schema</h2>
67+
## Polygon Schema {#polygons}
6868

6969
GeoJSON polygons let you define an arbitrary shape on a map. For example,
7070
the below polygon is a GeoJSON rectangle that approximates the border
@@ -106,7 +106,7 @@ const citySchema = new mongoose.Schema({
106106
});
107107
```
108108

109-
<h2 id="querying">Geospatial Queries with Mongoose</h2>
109+
## Geospatial Queries with Mongoose {#querying}
110110

111111
Mongoose queries support the same [geospatial query operators](http://thecodebarbarian.com/80-20-guide-to-mongodb-geospatial-queries)
112112
that the MongoDB driver does. For example, the below script saves a
@@ -128,7 +128,7 @@ that's a shorthand for `$geoWithin`.
128128
[require:geojson.*within helper]
129129
```
130130

131-
<h2 id="geospatial-indexes">Geospatial Indexes</h2>
131+
## Geospatial Indexes {#geospatial-indexes}
132132

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

0 commit comments

Comments
 (0)