Skip to content

Commit

Permalink
Merge pull request #13173 from hasezoey/fixHeaderLevels
Browse files Browse the repository at this point in the history
Change Documentation heading levels to be consistent across files
  • Loading branch information
vkarpov15 committed Mar 22, 2023
2 parents 765b861 + 27d412c commit 9db3382
Show file tree
Hide file tree
Showing 34 changed files with 347 additions and 351 deletions.
4 changes: 2 additions & 2 deletions docs/advanced_schemas.md
@@ -1,6 +1,6 @@
## Advanced Schemas
# Advanced Schemas

### Creating from ES6 Classes Using `loadClass()`
## Creating from ES6 Classes Using `loadClass()`

Mongoose allows creating schemas from [ES6 classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
The `loadClass()` function lets you pull in methods,
Expand Down
6 changes: 3 additions & 3 deletions docs/async-await.md
Expand Up @@ -4,7 +4,7 @@
* [Async Functions](#async-functions)
* [Queries](#queries)

### Basic Use
## Basic Use

Async/await lets us write asynchronous code as if it were synchronous.
This is especially helpful for avoiding callback hell when executing multiple async operations in sequence--a common scenario when working with Mongoose.
Expand Down Expand Up @@ -64,7 +64,7 @@ async function awaitUpdate() {

Note that the specific fulfillment values of different Mongoose methods vary, and may be affected by configuration. Please refer to the [API documentation](api/mongoose.html.html) for information about specific methods.

### Async Functions
## Async Functions

Adding the keyword *async* to a JavaScript function automatically causes it to return a native JavaScript promise.
This is true [regardless of the return value we specify in the function body](http://thecodebarbarian.com/async-functions-in-javascript.html#an-async-function-always-returns-a-promise).
Expand Down Expand Up @@ -102,7 +102,7 @@ async function doStuffWithUser() {
}
```

<h3 id="queries">Async/Await with Mongoose Queries</h3>
<h2 id="queries">Async/Await with Mongoose Queries</h2>

Under the hood, [async/await is syntactic sugar](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await) over the Promise API.
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.
Expand Down
4 changes: 2 additions & 2 deletions docs/change-streams.md
@@ -1,4 +1,4 @@
## Change Streams
# Change Streams

[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.
Expand Down Expand Up @@ -48,7 +48,7 @@ MongoServerError: The $changeStream stage is only supported on replica sets
If you're using `watch()` in production, we recommend using [MongoDB Atlas](https://www.mongodb.com/atlas/database).
For local development, we recommend [mongodb-memory-server](https://www.npmjs.com/package/mongodb-memory-server) or [run-rs](https://www.npmjs.com/package/run-rs) to start a replica set locally.

### Iterating using `next()`
## Iterating using `next()`

If you want to iterate through a change stream in a [AWS Lambda function](lambda.html), do **not** use event emitters to listen to the change stream.
You need to make sure you close your change stream when your Lambda function is done executing, because your change stream may end up in an inconsistent state if Lambda stops your container while the change stream is pulling data from MongoDB.
Expand Down
30 changes: 15 additions & 15 deletions docs/connections.md
@@ -1,4 +1,4 @@
## Connections
# Connections

You can connect to MongoDB with the `mongoose.connect()` method.

Expand Down Expand Up @@ -33,7 +33,7 @@ See the [mongodb connection string spec](http://www.mongodb.com/docs/manual/refe
<li><a href="#connection_pools">Connection Pools</a></li>
</ul>

<h3 id="buffering"><a href="#buffering">Operation Buffering</a></h3>
<h2 id="buffering"><a href="#buffering">Operation Buffering</a></h2>

Mongoose lets you start using your models immediately, without waiting for
mongoose to establish a connection to MongoDB.
Expand Down Expand Up @@ -91,7 +91,7 @@ const Model = mongoose.model('Test', schema);
await Model.createCollection();
```

<h3 id="error-handling"><a href="#error-handling">Error Handling</a></h3>
<h2 id="error-handling"><a href="#error-handling">Error Handling</a></h2>

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

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

<h3 id="options"><a href="#options">Options</a></h3>
<h2 id="options"><a href="#options">Options</a></h2>

The `connect` method also accepts an `options` object which will be passed
on to the underlying MongoDB driver.
Expand Down Expand Up @@ -175,7 +175,7 @@ mongoose.connect(uri, options);

See [this page](http://mongodb.github.io/node-mongodb-native/3.1/reference/faq/) for more information about `connectTimeoutMS` and `socketTimeoutMS`

<h3 id="callback"><a href="#callback">Callback</a></h3>
<h2 id="callback"><a href="#callback">Callback</a></h2>

The `connect()` function also accepts a callback parameter and returns a
[promise](promises.html).
Expand All @@ -192,7 +192,7 @@ mongoose.connect(uri, options).then(
);
```

<h3 id="connection-string-options"><a href="#connection-string-options">Connection String Options</a></h3>
<h2 id="connection-string-options"><a href="#connection-string-options">Connection String Options</a></h2>

You can also specify driver options in your connection string as
[parameters in the query string](https://en.wikipedia.org/wiki/Query_string)
Expand Down Expand Up @@ -225,7 +225,7 @@ 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://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>
<h2 id="connection-events"><a href="#connection-events">Connection Events</a></h2>

Connections inherit from [Node.js' `EventEmitter` class](https://nodejs.org/api/events.html#events_class_eventemitter),
and emit events when something happens to the connection, like losing
Expand All @@ -247,7 +247,7 @@ When you're connecting to a single MongoDB server (a "standalone"), Mongoose wil
disconnected from the standalone server, and 'connected' if it successfully connects to the standalone. In a
replica set, Mongoose will emit 'disconnected' if it loses connectivity to the replica set primary, and 'connected' if it manages to reconnect to the replica set primary.

<h3 id="keepAlive"><a href="#keepAlive">A note about keepAlive</a></h3>
<h2 id="keepAlive"><a href="#keepAlive">A note about keepAlive</a></h2>

For long running applications, it is often prudent to enable `keepAlive`
with a number of milliseconds. Without it, after some period of time
Expand All @@ -263,7 +263,7 @@ mongoose.connect(uri, { keepAlive: true, keepAliveInitialDelay: 300000 });
`keepAliveInitialDelay` is the number of milliseconds to wait before initiating `keepAlive` on the socket.
`keepAlive` is true by default since mongoose 5.2.0.

<h3 id="replicaset_connections"><a href="#replicaset_connections">Replica Set Connections</a></h3>
<h2 id="replicaset_connections"><a href="#replicaset_connections">Replica Set Connections</a></h2>

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

<h3 id="server-selection"><a href="#server-selection">Server Selection</a></h3>
<h2 id="server-selection"><a href="#server-selection">Server Selection</a></h2>

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.
If the MongoDB driver can't find a server to send an operation to after `serverSelectionTimeoutMS`,
Expand Down Expand Up @@ -319,7 +319,7 @@ mongoose.connect(uri, {
}).catch(err => console.log(err.reason));
```

<h3 id="replicaset-hostnames"><a href="#replicaset-hostnames">Replica Set Host Names</a></h3>
<h2 id="replicaset-hostnames"><a href="#replicaset-hostnames">Replica Set Host Names</a></h2>

MongoDB replica sets rely on being able to reliably figure out the domain name for each member.
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.
Expand Down Expand Up @@ -352,7 +352,7 @@ if (err.name === 'MongooseServerSelectionError') {
}
```

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

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
Expand All @@ -363,7 +363,7 @@ for high availability in a sharded cluster. You do
mongoose.connect('mongodb://mongosA:27501,mongosB:27501', cb);
```

<h3 id="multiple_connections"><a href="#multiple_connections">Multiple connections</a></h3>
<h2 id="multiple_connections"><a href="#multiple_connections">Multiple connections</a></h2>

So far we've seen how to connect to MongoDB using Mongoose's default
connection. Mongoose creates a _default connection_ when you call `mongoose.connect()`.
Expand Down Expand Up @@ -441,7 +441,7 @@ module.exports = function connectionFactory() {
};
```

<h3 id="connection_pools"><a href="#connection_pools">Connection Pools</a></h3>
<h2 id="connection_pools"><a href="#connection_pools">Connection Pools</a></h2>

Each `connection`, whether created with `mongoose.connect` or
`mongoose.createConnection` are all backed by an internal configurable
Expand All @@ -457,6 +457,6 @@ const uri = 'mongodb://127.0.0.1:27017/test?maxPoolSize=10';
mongoose.createConnection(uri);
```

<h3 id="next">Next Up</h3>
<h2 id="next">Next Up</h2>

Now that we've covered connections, let's take a look at [models](models.html).
4 changes: 2 additions & 2 deletions docs/customschematypes.md
@@ -1,6 +1,6 @@
## Custom Schema Types
# Custom Schema Types

### Creating a Basic Custom Schema Type
## Creating a Basic Custom Schema Type

_New in Mongoose 4.4.0:_ Mongoose supports custom types. Before you
reach for a custom type, however, know that a custom type is overkill
Expand Down
10 changes: 5 additions & 5 deletions docs/defaults.md
@@ -1,6 +1,6 @@
## Defaults
# Defaults

### Declaring Defaults in Your Schema
## Declaring Defaults in Your Schema

Your schemas can define default values for certain paths. If you create
a new document without that path set, the default will kick in.
Expand All @@ -12,7 +12,7 @@ strictly `undefined`.
[require:Declaring defaults in your schema]
```

### Default Functions
## Default Functions

You can also set the `default` schema option to a function. Mongoose will
execute that function and use the return value as the default.
Expand All @@ -21,7 +21,7 @@ execute that function and use the return value as the default.
[require:Default functions]
```

### The `setDefaultsOnInsert` Option
## 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://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/).
You can disable this behavior by setting the `setDefaultsOnInsert` option to `false`.
Expand All @@ -36,7 +36,7 @@ You can also set `setDefaultsOnInsert` to `false` globally:
mongoose.set('setDefaultsOnInsert', false);
```

### Default functions and `this`
## Default functions and `this`

Unless it is running on a query with `setDefaultsOnInsert`, a default
function's `this` refers to the document.
Expand Down
10 changes: 5 additions & 5 deletions docs/discriminators.md
@@ -1,6 +1,6 @@
## Discriminators
# Discriminators

### The `model.discriminator()` function
## The `model.discriminator()` function

Discriminators are a schema inheritance mechanism. They enable
you to have multiple models with overlapping schemas on top of the
Expand All @@ -18,7 +18,7 @@ is the union of the base schema and the discriminator schema.
[require:The `model.discriminator\(\)` function]
```

### Discriminators save to the Event model's collection
## Discriminators save to the Event model's collection

Suppose you created another discriminator to track events where
a new user registered. These `SignedUpEvent` instances will be
Expand All @@ -29,7 +29,7 @@ instances.
[require:Discriminators save to the Event model's collection]
```

### Discriminator keys
## Discriminator keys

The way Mongoose tells the difference between the different discriminator models is by the 'discriminator key', which is `__t` by default.
Mongoose adds a String path called `__t` to your schemas that it uses to track which discriminator this document is an instance of.
Expand All @@ -38,7 +38,7 @@ Mongoose adds a String path called `__t` to your schemas that it uses to track w
[require:Discriminator keys]
```

### Updating the discriminator key
## Updating the discriminator key

By default, Mongoose doesn't let you update the discriminator key.
`save()` will throw an error if you attempt to update the discriminator key.
Expand Down
4 changes: 2 additions & 2 deletions docs/documents.md
@@ -1,4 +1,4 @@
## Documents
# Documents

Mongoose [documents](api/document.html) represent a one-to-one mapping
to documents as stored in MongoDB. Each document is an instance of its
Expand Down Expand Up @@ -158,7 +158,7 @@ The other way is to use [`Model.replaceOne()`](api/model.html#model_Model-replac
await Person.replaceOne({ _id }, { name: 'Jean-Luc Picard' });
```

### Next Up
## Next Up

Now that we've covered Documents, let's take a look at
[Subdocuments](subdocs.html).
6 changes: 3 additions & 3 deletions docs/enterprise.md
@@ -1,7 +1,7 @@
# Mongoose for Enterprise

### Available as part of the Tidelift Subscription
## Available as part of the Tidelift Subscription

Tidelift is working with the maintainers of Mongoose and thousands of other
open source projects to deliver commercial support and maintenance for the
open source dependencies you use to build your applications. Save time,
Expand All @@ -15,7 +15,7 @@ exact dependencies you use.
<button style="border-radius: 3px;padding: 3px;padding-left: 30px;padding-right: 30px;border: 1px solid transparent;color: white;background-color: #800;">Request a Demo</button>
</a>

### Enterprise-ready open source software—managed for you
## Enterprise-ready open source software—managed for you

The Tidelift Subscription is a managed open source subscription for application
dependencies covering millions of open source projects across JavaScript,
Expand Down
2 changes: 1 addition & 1 deletion docs/faq.md
@@ -1,4 +1,4 @@
## FAQ
# FAQ

<style>
hr {
Expand Down

0 comments on commit 9db3382

Please sign in to comment.