diff --git a/.gitignore b/.gitignore
index 361b203fffb..d84960d7861 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@ benchmarks/benchmarks
benchmarks/benchmarks2
benchmarks/benchmarks3
benchmarks/v8.log
+benchmarks/typescript/**/*.js
.DS_Store
docs/*.json
docs/source/_docs
@@ -40,11 +41,23 @@ test/files/main.js
package-lock.json
-.config*
+.config.js
# Compiled docs
docs/*.html
docs/tutorials/*.html
docs/typescript/*.html
docs/api/*.html
-index.html
\ No newline at end of file
+index.html
+
+# Local Netlify folder
+.netlify
+
+# yarn package-lock
+yarn.lock
+
+# npm pack output
+mongoose.tgz
+mongoose-*.tgz
+
+examples/ecommerce-netlify-functions/.netlify/state.json
diff --git a/docs/async-await.md b/docs/async-await.md
index d68616299f4..fdc223e060e 100644
--- a/docs/async-await.md
+++ b/docs/async-await.md
@@ -62,7 +62,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.html) for information about specific methods.
+Note that the specific fulfillment values of different Mongoose methods vary, and may be affected by configuration. Please refer to the [API documentation](api.html) for information about specific methods.
### Async Functions
@@ -108,7 +108,7 @@ Under the hood, [async/await is syntactic sugar](https://developer.mozilla.org/e
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.
Such objects belong to a broader class of objects called [thenables](https://masteringjs.io/tutorials/fundamentals/thenable).
If the thenable being unwrapped is a genuine promise, e.g. an instance of the [Promise constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), we enjoy several guarantees about how the object’s ‘then’ function will behave.
-However, Mongoose provides several static helper methods that return a different class of thenable object called a [Query](./queries.html)--and [Queries are not promises](./queries.html#queries-are-not-promises).
+However, Mongoose provides several static helper methods that return a different class of thenable object called a [Query](queries.html)--and [Queries are not promises](queries.html#queries-are-not-promises).
Because Queries are also *thenables*, we can interact with a Query using async/await just as we would interact with a genuine promise, with one key difference: observing the fulfillment value of a genuine promise cannot under any circumstances change that value, but trying to re-observe the value of a Query may cause the Query to be re-executed.
```javascript
@@ -148,4 +148,4 @@ async function observeQuery() {
You are most likely to accidentally re-execute queries in this way when mixing callbacks with async/await.
This is never necessary and should be avoided.
- If you need a Query to return a fully-fleged promise instead of a thenable, you can use [Query#exec()](./api/query.html#query_Query-exec).
\ No newline at end of file
+ If you need a Query to return a fully-fleged promise instead of a thenable, you can use [Query#exec()](api/query.html#query_Query-exec).
diff --git a/docs/connections.md b/docs/connections.md
index c77239df486..0f03585fea9 100644
--- a/docs/connections.md
+++ b/docs/connections.md
@@ -61,7 +61,7 @@ setTimeout(function() {
}, 60000);
```
-To disable buffering, turn off the [`bufferCommands` option on your schema](./guide.html#bufferCommands).
+To disable buffering, turn off the [`bufferCommands` option on your schema](guide.html#bufferCommands).
If you have `bufferCommands` on and your connection is hanging, try turning
`bufferCommands` off to see if you haven't opened a connection properly.
You can also disable `bufferCommands` globally:
@@ -71,11 +71,11 @@ mongoose.set('bufferCommands', false);
```
Note that buffering is also responsible for waiting until Mongoose
-creates collections if you use the [`autoCreate` option](/docs/guide.html#autoCreate).
+creates collections if you use the [`autoCreate` option](guide.html#autoCreate).
If you disable buffering, you should also disable the `autoCreate`
-option and use [`createCollection()`](/docs/api/model.html#model_Model.createCollection)
-to create [capped collections](/docs/guide.html#capped) or
-[collections with collations](/docs/guide.html#collation).
+option and use [`createCollection()`](api/model.html#model_Model.createCollection)
+to create [capped collections](guide.html#capped) or
+[collections with collations](guide.html#collation).
```javascript
const schema = new Schema({
@@ -149,7 +149,7 @@ Below are some of the options that are important for tuning Mongoose.
* `useNewUrlParser` - The underlying MongoDB driver has deprecated their current [connection string](https://docs.mongodb.com/manual/reference/connection-string/) parser. Because this is a major change, they added the `useNewUrlParser` flag to allow users to fall back to the old parser if they find a bug in the new parser. You should set `useNewUrlParser: true` unless that prevents you from connecting. Note that if you specify `useNewUrlParser: true`, you **must** specify a port in your connection string, like `mongodb://localhost:27017/dbname`. The new url parser does _not_ support connection strings that do not have a port, like `mongodb://localhost/dbname`.
* `useCreateIndex` - False by default. Set to `true` to make Mongoose's default index build use `createIndex()` instead of `ensureIndex()` to avoid deprecation warnings from the MongoDB driver.
* `useFindAndModify` - True by default. Set to `false` to make `findOneAndUpdate()` and `findOneAndRemove()` use native `findOneAndUpdate()` rather than `findAndModify()`.
-* `useUnifiedTopology`- False by default. Set to `true` to opt in to using [the MongoDB driver's new connection management engine](/docs/deprecations.html#useunifiedtopology). You should set this option to `true`, except for the unlikely case that it prevents you from maintaining a stable connection.
+* `useUnifiedTopology`- False by default. Set to `true` to opt in to using [the MongoDB driver's new connection management engine](deprecations.html#useunifiedtopology). You should set this option to `true`, except for the unlikely case that it prevents you from maintaining a stable connection.
* `promiseLibrary` - Sets the [underlying driver's promise library](http://mongodb.github.io/node-mongodb-native/3.1/api/MongoClient.html).
* `poolSize` - The maximum number of sockets the MongoDB driver will keep open for this connection. By default, `poolSize` is 5. Keep in mind that, as of MongoDB 3.4, 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).
* `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.
@@ -157,7 +157,7 @@ Below are some of the options that are important for tuning Mongoose.
* `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.
The following options are important for tuning Mongoose only if you are
-running **without** [the `useUnifiedTopology` option](/docs/deprecations.html#useunifiedtopology):
+running **without** [the `useUnifiedTopology` option](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.
@@ -166,7 +166,7 @@ running **without** [the `useUnifiedTopology` option](/docs/deprecations.html#us
* `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):
+running **with** [the `useUnifiedTopology` option](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.
@@ -199,7 +199,7 @@ See [this page](http://mongodb.github.io/node-mongodb-native/3.1/reference/faq/)
The `connect()` function also accepts a callback parameter and returns a
-[promise](./promises.html).
+[promise](promises.html).
```javascript
mongoose.connect(uri, options, function(error) {
@@ -396,8 +396,8 @@ The `mongoose.createConnection()` function takes the same arguments as
const conn = mongoose.createConnection('mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]', options);
```
-This [connection](./api.html#connection_Connection) object is then used to
-create and retrieve [models](./api.html#model_Model). Models are
+This [connection](api.html#connection_Connection) object is then used to
+create and retrieve [models](api.html#model_Model). Models are
**always** scoped to a single connection.
```javascript
@@ -526,4 +526,4 @@ mongoose.connect(myUri, {
Next Up
-Now that we've covered connections, let's take a look at [models](/docs/models.html).
\ No newline at end of file
+Now that we've covered connections, let's take a look at [models](models.html).
diff --git a/docs/deprecations.md b/docs/deprecations.md
index b17953659c0..fe007b36139 100644
--- a/docs/deprecations.md
+++ b/docs/deprecations.md
@@ -32,15 +32,15 @@ removed in a future version. To use the new parser, pass option
The MongoDB Node.js driver rewrote the tool it uses to parse [MongoDB connection strings](https://docs.mongodb.com/manual/reference/connection-string/).
Because this is such a big change, they put the new connection string parser
behind a flag. To turn on this option, pass the `useNewUrlParser` option to
-[`mongoose.connect()`](/docs/api.html#mongoose_Mongoose-connect)
-or [`mongoose.createConnection()`](/docs/api.html#mongoose_Mongoose-createConnection).
+[`mongoose.connect()`](api.html#mongoose_Mongoose-connect)
+or [`mongoose.createConnection()`](api.html#mongoose_Mongoose-createConnection).
```javascript
mongoose.connect(uri, { useNewUrlParser: true });
mongoose.createConnection(uri, { useNewUrlParser: true });
```
-You can also [set the global `useNewUrlParser` option](/docs/api.html#mongoose_Mongoose-set)
+You can also [set the global `useNewUrlParser` option](api.html#mongoose_Mongoose-set)
to turn on `useNewUrlParser` for every connection by default.
```javascript
@@ -56,7 +56,7 @@ with `{ useNewUrlParser: true }`, please [open an issue on GitHub](https://githu
-If you use [`Model.findOneAndUpdate()`](/docs/api.html#model_Model.findOneAndUpdate),
+If you use [`Model.findOneAndUpdate()`](api.html#model_Model.findOneAndUpdate),
by default you'll see one of the below deprecation warnings.
```
@@ -67,7 +67,7 @@ DeprecationWarning: collection.findAndModify is deprecated. Use findOneAndUpdate
Mongoose's `findOneAndUpdate()` long pre-dates the MongoDB driver's `findOneAndUpdate()`
function, so it uses the MongoDB driver's [`findAndModify()` function](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#findAndModify)
instead. You can opt in to using the MongoDB driver's `findOneAndUpdate()`
-function using the [`useFindAndModify` global option](/docs/api.html#mongoose_Mongoose-set).
+function using the [`useFindAndModify` global option](api.html#mongoose_Mongoose-set).
```javascript
// Make Mongoose use `findOneAndUpdate()`. Note that this option is `true`
@@ -86,22 +86,22 @@ no intentional backwards breaking changes, so you should be able to turn
this option on without any code changes. If you discover any issues,
please [open an issue on GitHub](https://github.com/Automattic/mongoose/issues/new).
-* [`Model.findByIdAndDelete()`](/docs/api.html#model_Model.findByIdAndDelete)
-* [`Model.findByIdAndRemove()`](/docs/api.html#model_Model.findByIdAndRemove)
-* [`Model.findByIdAndUpdate()`](/docs/api.html#model_Model.findByIdAndUpdate)
-* [`Model.findOneAndDelete()`](/docs/api.html#model_Model.findOneAndDelete)
-* [`Model.findOneAndRemove()`](/docs/api.html#model_Model.findOneAndRemove)
-* [`Model.findOneAndUpdate()`](/docs/api.html#model_Model.findOneAndUpdate)
-* [`Query.findOneAndDelete()`](/docs/api.html#query_Query-findOneAndDelete)
-* [`Query.findOneAndRemove()`](/docs/api.html#query_Query-findOneAndRemove)
-* [`Query.findOneAndUpdate()`](/docs/api.html#query_Query-findOneAndUpdate)
+* [`Model.findByIdAndDelete()`](api.html#model_Model.findByIdAndDelete)
+* [`Model.findByIdAndRemove()`](api.html#model_Model.findByIdAndRemove)
+* [`Model.findByIdAndUpdate()`](api.html#model_Model.findByIdAndUpdate)
+* [`Model.findOneAndDelete()`](api.html#model_Model.findOneAndDelete)
+* [`Model.findOneAndRemove()`](api.html#model_Model.findOneAndRemove)
+* [`Model.findOneAndUpdate()`](api.html#model_Model.findOneAndUpdate)
+* [`Query.findOneAndDelete()`](api.html#query_Query-findOneAndDelete)
+* [`Query.findOneAndRemove()`](api.html#query_Query-findOneAndRemove)
+* [`Query.findOneAndUpdate()`](api.html#query_Query-findOneAndUpdate)
You can also safely ignore this warning. Mongoose will not remove the legacy `useFindAndModify: true`
behavior until Mongoose 6.0.
-If you define [indexes in your Mongoose schemas](https://mongoosejs.com/docs/guide.html#indexes), you'll see the below
+If you define [indexes in your Mongoose schemas](guide.html#indexes), you'll see the below
deprecation warning.
```
@@ -111,7 +111,7 @@ instead.
By default, Mongoose 5.x calls the [MongoDB driver's `ensureIndex()` function](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#ensureIndex).
The MongoDB driver deprecated this function in favor of [`createIndex()`](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#createIndex).
-Set the [`useCreateIndex` global option](/docs/api.html#mongoose_Mongoose-set) to opt in to making Mongoose use `createIndex()` instead.
+Set the [`useCreateIndex` global option](api.html#mongoose_Mongoose-set) to opt in to making Mongoose use `createIndex()` instead.
```javascript
mongoose.set('useCreateIndex', true);
@@ -144,7 +144,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()`](/docs/api.html#model_Model.remove). The `single`
+`deleteMany()`, _unless_ you specify the [`single` option to `remove()`](api.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)`.
@@ -183,7 +183,7 @@ mongoose.set('useUnifiedTopology', true);
```
The `useUnifiedTopology` option removes support for several
-[connection options](/docs/connections.html#options) that are
+[connection options](connections.html#options) that are
no longer relevant with the new topology engine:
- `autoReconnect`
@@ -191,16 +191,16 @@ no longer relevant with the new topology engine:
- `reconnectInterval`
When you enable `useUnifiedTopology`, please remove those options
-from your [`mongoose.connect()`](/docs/api/mongoose.html#mongoose_Mongoose-connect) or
-[`createConnection()`](/docs/api/mongoose.html#mongoose_Mongoose-createConnection) calls.
+from your [`mongoose.connect()`](api/mongoose.html#mongoose_Mongoose-connect) or
+[`createConnection()`](api/mongoose.html#mongoose_Mongoose-createConnection) calls.
If you find any unexpected behavior, please [open up an issue on GitHub](https://github.com/Automattic/mongoose/issues/new).
-Like `remove()`, the [`update()` function](/docs/api.html#model_Model.update) is deprecated in favor
-of the more explicit [`updateOne()`](/docs/api.html#model_Model.updateOne), [`updateMany()`](/docs/api.html#model_Model.updateMany), and [`replaceOne()`](/docs/api.html#model_Model.replaceOne) functions. You should replace
-`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](/docs/api.html#model_Model.update).
+Like `remove()`, the [`update()` function](api.html#model_Model.update) is deprecated in favor
+of the more explicit [`updateOne()`](api.html#model_Model.updateOne), [`updateMany()`](api.html#model_Model.updateMany), and [`replaceOne()`](api.html#model_Model.replaceOne) functions. You should replace
+`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](api.html#model_Model.update).
```
collection.update is deprecated. Use updateOne, updateMany, or bulkWrite
@@ -290,4 +290,4 @@ const writeStream = gfs.createWriteStream({ filename: 'test.dat' });
const conn = mongoose.createConnection('mongodb://localhost:27017/gfstest');
const gridFSBucket = new mongoose.mongo.GridFSBucket(conn.db);
const writeStream = gridFSBucket.openUploadStream('test.dat');
-```
\ No newline at end of file
+```
diff --git a/docs/documents.md b/docs/documents.md
index 5c762adc7f9..eff8ea84861 100644
--- a/docs/documents.md
+++ b/docs/documents.md
@@ -1,8 +1,8 @@
## Documents
-Mongoose [documents](./api/document.html) represent a one-to-one mapping
+Mongoose [documents](api/document.html) represent a one-to-one mapping
to documents as stored in MongoDB. Each document is an instance of its
-[Model](./models.html).
+[Model](models.html).
- Documents vs Models
@@ -134,13 +134,13 @@ await Person.updateOne({}, { age: 'bar' });
await Person.updateOne({}, { age: -1 }, { runValidators: true });
```
-Read the [validation](./validation.html) guide for more details.
+Read the [validation](validation.html) guide for more details.
There are 2 different ways to overwrite a document (replacing all keys in the
document). One way is to use the
-[`Document#overwrite()` function](/docs/api/document.html#document_Document-overwrite)
+[`Document#overwrite()` function](api/document.html#document_Document-overwrite)
followed by `save()`.
```javascript
@@ -151,7 +151,7 @@ doc.overwrite({ name: 'Jean-Luc Picard' });
await doc.save();
```
-The other way is to use [`Model.replaceOne()`](/docs/api/model.html#model_Model.replaceOne).
+The other way is to use [`Model.replaceOne()`](api/model.html#model_Model.replaceOne).
```javascript
// Sets `name` and unsets all other properties
@@ -161,4 +161,4 @@ await Person.replaceOne({ _id }, { name: 'Jean-Luc Picard' });
### Next Up
Now that we've covered Documents, let's take a look at
-[Subdocuments](/docs/subdocs.html).
\ No newline at end of file
+[Subdocuments](subdocs.html).
diff --git a/docs/faq.md b/docs/faq.md
index 33cc25e3f2e..f8a5a3303cd 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -25,8 +25,8 @@ doc.save();
**A**. Mongoose doesn't create getters/setters for array indexes; without
them mongoose never gets notified of the change and so doesn't know to
persist the new value. There are two workarounds:
-[`MongooseArray#set`](./api.html#types_array_MongooseArray.set) or
-[`Document#markModified()`](/docs/api/document.html#document_Document-markModified).
+[`MongooseArray#set`](api.html#types_array_MongooseArray.set) or
+[`Document#markModified()`](api/document.html#document_Document-markModified).
```javascript
// Saves changes successfully
@@ -123,7 +123,7 @@ console.log(new Model());
**A**. This is a performance optimization. These empty objects are not saved
to the database, nor are they in the result `toObject()`, nor do they show
-up in `JSON.stringify()` output unless you turn off the [`minimize` option](./guide.html#minimize).
+up in `JSON.stringify()` output unless you turn off the [`minimize` option](guide.html#minimize).
The reason for this behavior is that Mongoose's change detection
and getters/setters are based on [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty).
@@ -132,7 +132,7 @@ the overhead of running `Object.defineProperty()` every time a document is creat
mongoose defines properties on the `Model` prototype when the model is compiled.
Because mongoose needs to define getters and setters for `nested.prop`, `nested`
must always be defined as an object on a mongoose document, even if `nested`
-is undefined on the underlying [POJO](./guide.html#minimize).
+is undefined on the underlying [POJO](guide.html#minimize).
@@ -141,7 +141,7 @@ is undefined on the underlying [POJO](./guide.html#minimize).
**A**. The only import syntax Mongoose supports is `import mongoose from 'mongoose'`.
Syntaxes like `import * from 'mongoose'` or `import { model } from 'mongoose'` do **not** work.
-The global Mongoose object stores types, [global options](/docs/api.html#mongoose_Mongoose-set), and other important
+The global Mongoose object stores types, [global options](api.html#mongoose_Mongoose-set), and other important
properties that Mongoose needs. When you do `import { model } from 'mongoose'`, the
`this` value in `model()` is not the Mongoose global.
@@ -161,7 +161,7 @@ foo(); // "undefined"
-**Q**. I'm using an arrow function for a [virtual](./guide.html#virtuals), [middleware](./middleware.html), [getter](./api.html#schematype_SchemaType-get)/[setter](./api.html#schematype_SchemaType-set), or [method](./guide.html#methods) and the value of `this` is wrong.
+**Q**. I'm using an arrow function for a [virtual](guide.html#virtuals), [middleware](middleware.html), [getter](api.html#schematype_SchemaType-get)/[setter](api.html#schematype_SchemaType-set), or [method](guide.html#methods) and the value of `this` is wrong.
**A**. Arrow functions [handle the `this` keyword much differently than conventional functions](https://masteringjs.io/tutorials/fundamentals/arrow#why-not-arrow-functions).
Mongoose getters/setters depend on `this` to give you access to the document that you're writing to, but this functionality does not work with arrow functions. Do **not** use arrow functions for mongoose getters/setters unless do not intend to access the document in the getter/setter.
@@ -254,7 +254,7 @@ new Schema({
**Q**. All function calls on my models hang, what am I doing wrong?
**A**. By default, mongoose will buffer your function calls until it can
-connect to MongoDB. Read the [buffering section of the connection docs](./connections.html#buffering)
+connect to MongoDB. Read the [buffering section of the connection docs](connections.html#buffering)
for more information.
@@ -274,7 +274,7 @@ mongoose.set('debug', { color: false })
mongoose.set('debug', { shell: true })
```
-For more debugging options (streams, callbacks), see the ['debug' option under `.set()`](./api.html#mongoose_Mongoose-set).
+For more debugging options (streams, callbacks), see the ['debug' option under `.set()`](api.html#mongoose_Mongoose-set).
@@ -425,7 +425,7 @@ Consider using a regex like `/^[a-f0-9]{24}$/` to test whether a string is exact
**A**. In order to avoid executing a separate query for each document returned from the `find` query, Mongoose
instead queries using (numDocuments * limit) as the limit. If you need the correct limit, you should use the
-[perDocumentLimit](/docs/populate.html#limit-vs-perDocumentLimit) option (new in Mongoose 5.9.0). Just keep in
+[perDocumentLimit](populate.html#limit-vs-perDocumentLimit) option (new in Mongoose 5.9.0). Just keep in
mind that populate() will execute a separate query for each document.
@@ -458,4 +458,4 @@ await BlogPost.updateOne({ title: 'Introduction to Promises' }, update, (err, re
**Something to add?**
-If you'd like to contribute to this page, please [visit it](https://github.com/Automattic/mongoose/tree/master/docs/faq.md) on github and use the [Edit](https://github.com/blog/844-forking-with-the-edit-button) button to send a pull request.
\ No newline at end of file
+If you'd like to contribute to this page, please [visit it](https://github.com/Automattic/mongoose/tree/master/docs/faq.md) on github and use the [Edit](https://github.com/blog/844-forking-with-the-edit-button) button to send a pull request.
diff --git a/docs/geojson.md b/docs/geojson.md
index ac2a726cb7f..f0878a75858 100644
--- a/docs/geojson.md
+++ b/docs/geojson.md
@@ -50,7 +50,7 @@ const citySchema = new mongoose.Schema({
});
```
-Using [subdocuments](/docs/subdocs.html), you can define a common `pointSchema` and reuse it everywhere you want to store a GeoJSON point.
+Using [subdocuments](subdocs.html), you can define a common `pointSchema` and reuse it everywhere you want to store a GeoJSON point.
```javascript
const pointSchema = new mongoose.Schema({
@@ -131,7 +131,7 @@ a polygon representing the state of Colorado using
[require:geojson.*driver query]
```
-Mongoose also has a [`within()` helper](/docs/api.html#query_Query-within)
+Mongoose also has a [`within()` helper](api.html#query_Query-within)
that's a shorthand for `$geoWithin`.
```javascript
@@ -148,7 +148,7 @@ a 2dsphere index on a GeoJSON point:
[require:geojson.*index$]
```
-You can also define a geospatial index using the [`Schema#index()` function](/docs/api/schema.html#schema_Schema-index)
+You can also define a geospatial index using the [`Schema#index()` function](api/schema.html#schema_Schema-index)
as shown below.
```javascript
@@ -157,4 +157,4 @@ 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)
-_require_ a 2dsphere index.
\ No newline at end of file
+_require_ a 2dsphere index.
diff --git a/docs/guide.md b/docs/guide.md
index acf75a90487..e599ef309f5 100644
--- a/docs/guide.md
+++ b/docs/guide.md
@@ -1,7 +1,7 @@
## Schemas
-If you haven't yet done so, please take a minute to read the [quickstart](./index.html) to get an idea of how Mongoose works.
-If you are migrating from 4.x to 5.x please take a moment to read the [migration guide](/docs/migrating_to_5.html).
+If you haven't yet done so, please take a minute to read the [quickstart](index.html) to get an idea of how Mongoose works.
+If you are migrating from 4.x to 5.x please take a moment to read the [migration guide](migrating_to_5.html).
- Defining your schema
@@ -43,12 +43,12 @@ collection and defines the shape of the documents within that collection.
```
If you want to add additional keys later, use the
-[Schema#add](./api.html#schema_Schema-add) method.
+[Schema#add](api.html#schema_Schema-add) method.
Each key in our code `blogSchema` defines a property in our documents which
-will be cast to its associated [SchemaType](./api.html#schematype_SchemaType).
+will be cast to its associated [SchemaType](api.html#schematype_SchemaType).
For example, we've defined a property `title` which will be cast to the
-[String](./api.html#schema-string-js) SchemaType and property `date`
+[String](api.html#schema-string-js) SchemaType and property `date`
which will be cast to a `Date` SchemaType.
Notice above that if a property only requires a type, it can be specified using
@@ -63,34 +63,34 @@ In these cases, Mongoose only creates actual schema paths for leaves
in the tree. (like `meta.votes` and `meta.favs` above),
and the branches do not have actual paths. A side-effect of this is that `meta`
above cannot have its own validation. If validation is needed up the tree, a path
-needs to be created up the tree - see the [Subdocuments](./subdocs.html) section
-for more information on how to do this. Also read the [Mixed](./schematypes.html)
+needs to be created up the tree - see the [Subdocuments](subdocs.html) section
+for more information on how to do this. Also read the [Mixed](schematypes.html)
subsection of the SchemaTypes guide for some gotchas.
The permitted SchemaTypes are:
-* [String](./schematypes.html#strings)
-* [Number](./schematypes.html#numbers)
-* [Date](./schematypes.html#dates)
-* [Buffer](./schematypes.html#buffers)
-* [Boolean](./schematypes.html#booleans)
-* [Mixed](./schematypes.html#mixed)
-* [ObjectId](./schematypes.html#objectids)
-* [Array](./schematypes.html#arrays)
-* [Decimal128](./api.html#mongoose_Mongoose-Decimal128)
-* [Map](./schematypes.html#maps)
+* [String](schematypes.html#strings)
+* [Number](schematypes.html#numbers)
+* [Date](schematypes.html#dates)
+* [Buffer](schematypes.html#buffers)
+* [Boolean](schematypes.html#booleans)
+* [Mixed](schematypes.html#mixed)
+* [ObjectId](schematypes.html#objectids)
+* [Array](schematypes.html#arrays)
+* [Decimal128](api.html#mongoose_Mongoose-Decimal128)
+* [Map](schematypes.html#maps)
-Read more about [SchemaTypes here](./schematypes.html).
+Read more about [SchemaTypes here](schematypes.html).
Schemas not only define the structure of your document and casting of
properties, they also define document [instance methods](#methods),
[static Model methods](#statics), [compound indexes](#indexes),
-and document lifecycle hooks called [middleware](./middleware.html).
+and document lifecycle hooks called [middleware](middleware.html).
To use our schema definition, we need to convert our `blogSchema` into a
-[Model](./models.html) we can work with.
+[Model](models.html) we can work with.
To do so, we pass it into `mongoose.model(modelName, schema)`:
```javascript
@@ -137,8 +137,8 @@ await doc.save(); // works
-Instances of `Models` are [documents](./documents.html). Documents have
-many of their own [built-in instance methods](./api/document.html).
+Instances of `Models` are [documents](documents.html). Documents have
+many of their own [built-in instance methods](api/document.html).
We may also define our own custom document instance methods.
```javascript
@@ -163,8 +163,8 @@ to them.
});
```
-* Overwriting a default mongoose document method may lead to unpredictable results. See [this](./api.html#schema_Schema.reserved) for more details.
-* The example above uses the `Schema.methods` object directly to save an instance method. You can also use the `Schema.method()` helper as described [here](./api.html#schema_Schema-method).
+* Overwriting a default mongoose document method may lead to unpredictable results. See [this](api.html#schema_Schema.reserved) for more details.
+* The example above uses the `Schema.methods` object directly to save an instance method. You can also use the `Schema.method()` helper as described [here](api.html#schema_Schema-method).
* Do **not** declare methods using ES6 arrow functions (`=>`). Arrow functions [explicitly prevent binding `this`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#No_binding_of_this), so your method will **not** have access to the document and the above examples will not work.
@@ -173,7 +173,7 @@ You can also add static functions to your model. There are two equivalent
ways to add a static:
- Add a function property to `schema.statics`
-- Call the [`Schema#static()` function](/docs/api.html#schema_Schema-static)
+- Call the [`Schema#static()` function](api.html#schema_Schema-static)
```javascript
// Assign a function to the "statics" object of our animalSchema
@@ -194,7 +194,7 @@ Do **not** declare statics using ES6 arrow functions (`=>`). Arrow functions [ex
You can also add query helper functions, which are like instance methods
but for mongoose queries. Query helper methods let you extend mongoose's
-[chainable query builder API](./queries.html).
+[chainable query builder API](queries.html).
```javascript
animalSchema.query.byName = function(name) {
@@ -215,7 +215,7 @@ but for mongoose queries. Query helper methods let you extend mongoose's
MongoDB supports [secondary indexes](http://docs.mongodb.org/manual/indexes/).
-With mongoose, we define these indexes within our `Schema` [at](./api.html#schematype_SchemaType-index) [the](./api.html#schematype_SchemaType-unique) [path](./api.html#schematype_SchemaType-sparse) [level](./api.html#schema_date_SchemaDate-expires) or the `schema` level.
+With mongoose, we define these indexes within our `Schema` [at](api.html#schematype_SchemaType-index) [the](api.html#schematype_SchemaType-unique) [path](api.html#schematype_SchemaType-sparse) [level](api.html#schema_date_SchemaDate-expires) or the `schema` level.
Defining indexes at the schema level is necessary when creating
[compound indexes](https://docs.mongodb.com/manual/core/index-compound/).
@@ -259,11 +259,11 @@ building or an error occurred.
});
```
-See also the [Model#ensureIndexes](./api.html#model_Model.ensureIndexes) method.
+See also the [Model#ensureIndexes](api.html#model_Model.ensureIndexes) method.
-[Virtuals](./api.html#schema_Schema-virtual) are document properties that
+[Virtuals](api.html#schema_Schema-virtual) are document properties that
you can get and set but that do not get persisted to MongoDB. The getters
are useful for formatting or combining fields, while setters are useful for
de-composing a single value into multiple values for storage.
@@ -296,7 +296,7 @@ But [concatenating](https://masteringjs.io/tutorials/fundamentals/string-concat)
last name every time can get cumbersome.
And what if you want to do some extra processing on the name, like
[removing diacritics](https://www.npmjs.com/package/diacritics)? A
-[virtual property getter](./api.html#virtualtype_VirtualType-get) lets you
+[virtual property getter](api.html#virtualtype_VirtualType-get) lets you
define a `fullName` property that won't get persisted to MongoDB.
```javascript
@@ -316,7 +316,7 @@ If you use `toJSON()` or `toObject()` mongoose will *not* include virtuals
by default. This includes the output of calling [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
on a Mongoose document, because [`JSON.stringify()` calls `toJSON()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description).
Pass `{ virtuals: true }` to either
-[`toObject()`](./api.html#document_Document-toObject) or [`toJSON()`](./api.html#document_Document-toJSON).
+[`toObject()`](api.html#document_Document-toObject) or [`toJSON()`](api.html#document_Document-toJSON).
You can also add a custom setter to your virtual that will let you set both
first name and last name via the `fullName` virtual.
@@ -370,7 +370,7 @@ console.log(person); // { n: 'Not Val' }
```
You can also declare aliases on nested paths. It is easier to use nested
-schemas and [subdocuments](/docs/subdocs.html), but you can also declare
+schemas and [subdocuments](subdocs.html), but you can also declare
nested path aliases inline as long as you use the full nested path
`nested.myProp` as the alias.
@@ -412,7 +412,7 @@ Valid options:
- [toJSON](#toJSON)
- [toObject](#toObject)
- [typeKey](#typeKey)
-- [typePojoToMixed](/docs/schematypes.html#mixed)
+- [typePojoToMixed](schematypes.html#mixed)
- [useNestedStrict](#useNestedStrict)
- [validateBeforeSave](#validateBeforeSave)
- [versionKey](#versionKey)
@@ -425,9 +425,9 @@ Valid options:
-By default, Mongoose's [`init()` function](/docs/api.html#model_Model.init)
+By default, Mongoose's [`init()` function](api.html#model_Model.init)
creates all the indexes defined in your model's schema by calling
-[`Model.createIndexes()`](/docs/api.html#model_Model.createIndexes)
+[`Model.createIndexes()`](api.html#model_Model.createIndexes)
after you successfully connect to MongoDB. Creating indexes automatically is
great for development and test environments. But index builds can also create
significant load on your production database. If you want to manage indexes
@@ -440,7 +440,7 @@ Clock.ensureIndexes(callback);
```
The `autoIndex` option is set to `true` by default. You can change this
-default by setting [`mongoose.set('autoIndex', false);`](/docs/api/mongoose.html#mongoose_Mongoose-set)
+default by setting [`mongoose.set('autoIndex', false);`](api/mongoose.html#mongoose_Mongoose-set)
@@ -465,7 +465,7 @@ const Clock = mongoose.model('Clock', schema);
```
Unlike `autoIndex`, `autoCreate` is `false` by default. You can change this
-default by setting [`mongoose.set('autoCreate', true);`](/docs/api/mongoose.html#mongoose_Mongoose-set)
+default by setting [`mongoose.set('autoCreate', true);`](api/mongoose.html#mongoose_Mongoose-set)
@@ -518,7 +518,7 @@ new Schema({..}, { capped: { size: 1024, max: 1000, autoIndexId: true } });
Mongoose by default produces a collection name by passing the model name to
-the [utils.toCollectionName](./api.html#utils_exports.toCollectionName) method.
+the [utils.toCollectionName](api.html#utils_exports.toCollectionName) method.
This method pluralizes the name. Set this option if you need a different name
for your collection.
@@ -528,7 +528,7 @@ const dataSchema = new Schema({..}, { collection: 'data' });
-When you define a [discriminator](/docs/discriminators.html), Mongoose adds a path to your
+When you define a [discriminator](discriminators.html), Mongoose adds a path to your
schema that stores which discriminator a document is an instance of. By default, Mongoose
adds an `__t` path, but you can set `discriminatorKey` to overwrite this default.
@@ -569,8 +569,8 @@ console.log(p.id); // undefined
Mongoose assigns each of your schemas an `_id` field by default if one
-is not passed into the [Schema](/docs/api.html#schema-js) constructor.
-The type assigned is an [ObjectId](/docs/api.html#schema_Schema.Types)
+is not passed into the [Schema](api.html#schema-js) constructor.
+The type assigned is an [ObjectId](api.html#schema_Schema.Types)
to coincide with MongoDB's default behavior. If you don't want an `_id`
added to your schema at all, you may disable it using this option.
@@ -643,7 +643,7 @@ sam.$isEmpty('inventory'); // false
-Allows setting [query#read](/docs/api.html#query_Query-read) options at the
+Allows setting [query#read](api.html#query_Query-read) options at the
schema level, providing us a way to apply default
[ReadPreferences](http://docs.mongodb.org/manual/applications/replication/#replica-set-read-preference)
to all queries derived from a model.
@@ -811,11 +811,11 @@ console.log(m.toJSON()); // { _id: 504e0cd7dd992d9be2f20b6f, name: 'Max Headroom
console.log(JSON.stringify(m)); // { "_id": "504e0cd7dd992d9be2f20b6f", "name": "Max Headroom is my name" }
```
-To see all available `toJSON/toObject` options, read [this](/docs/api.html#document_Document-toObject).
+To see all available `toJSON/toObject` options, read [this](api.html#document_Document-toObject).
-Documents have a [toObject](/docs/api.html#document_Document-toObject) method
+Documents have a [toObject](api.html#document_Document-toObject) method
which converts the mongoose document into a plain JavaScript object. This
method accepts a few options. Instead of applying these options on a
per-document basis, we may declare the options at the schema level and have
@@ -835,7 +835,7 @@ const m = new M({ name: 'Max Headroom' });
console.log(m); // { _id: 504e0cd7dd992d9be2f20b6f, name: 'Max Headroom is my name' }
```
-To see all available `toObject` options, read [this](/docs/api.html#document_Document-toObject).
+To see all available `toObject` options, read [this](api.html#document_Document-toObject).
@@ -935,7 +935,7 @@ const thing = new Thing({ name: 'no versioning please' });
thing.save(); // { name: 'no versioning please' }
```
-Mongoose _only_ updates the version key when you use [`save()`](/docs/api.html#document_Document-save).
+Mongoose _only_ updates the version key when you use [`save()`](api.html#document_Document-save).
If you use `update()`, `findOneAndUpdate()`, etc. Mongoose will **not**
update the version key. As a workaround, you can use the below middleware.
@@ -1061,7 +1061,7 @@ thing.save(); // version is not incremented
The `timestamps` option tells mongoose to assign `createdAt` and `updatedAt` fields
-to your schema. The type assigned is [Date](./api.html#schema-date-js).
+to your schema. The type assigned is [Date](api.html#schema-date-js).
By default, the names of the fields are `createdAt` and `updatedAt`. Customize
the field names by setting `timestamps.createdAt` and `timestamps.updatedAt`.
@@ -1229,12 +1229,12 @@ new Parent({ child: {} }).validateSync().errors;
-Schemas have a [`loadClass()` method](/docs/api/schema.html#schema_Schema-loadClass)
+Schemas have a [`loadClass()` method](api/schema.html#schema_Schema-loadClass)
that you can use to create a Mongoose schema from an [ES6 class](https://thecodebarbarian.com/an-overview-of-es6-classes):
-* [ES6 class methods](https://masteringjs.io/tutorials/fundamentals/class#methods) become [Mongoose methods](/docs/guide.html#methods)
-* [ES6 class statics](https://masteringjs.io/tutorials/fundamentals/class#statics) become [Mongoose statics](/docs/guide.html#statics)
-* [ES6 getters and setters](https://masteringjs.io/tutorials/fundamentals/class#getterssetters) become [Mongoose virtuals](/docs/tutorials/virtuals.html)
+* [ES6 class methods](https://masteringjs.io/tutorials/fundamentals/class#methods) become [Mongoose methods](guide.html#methods)
+* [ES6 class statics](https://masteringjs.io/tutorials/fundamentals/class#statics) become [Mongoose statics](guide.html#statics)
+* [ES6 getters and setters](https://masteringjs.io/tutorials/fundamentals/class#getterssetters) become [Mongoose virtuals](tutorials/virtuals.html)
Here's an example of using `loadClass()` to create a schema from an ES6 class:
@@ -1255,7 +1255,7 @@ console.log(schema.virtuals); // { myVirtual: VirtualType { ... } }
-Schemas are also [pluggable](./plugins.html) which allows us to package up reusable features into
+Schemas are also [pluggable](plugins.html) which allows us to package up reusable features into
plugins that can be shared with the community or just between your projects.
Further Reading
@@ -1277,4 +1277,4 @@ of use cases, including e-commerce, wikis, and appointment bookings.
Next Up
-Now that we've covered `Schemas`, let's take a look at [SchemaTypes](/docs/schematypes.html).
+Now that we've covered `Schemas`, let's take a look at [SchemaTypes](schematypes.html).
diff --git a/docs/guides.md b/docs/guides.md
index c8196bfa341..5cdf9a1c06c 100644
--- a/docs/guides.md
+++ b/docs/guides.md
@@ -5,43 +5,42 @@ integrating Mongoose with external tools and frameworks.
### Mongoose Core Concepts
-* [Schemas](/docs/guide.html)
-* [SchemaTypes](/docs/schematypes.html)
-* [Connections](/docs/connections.html)
-* [Models](/docs/models.html)
-* [Documents](/docs/documents.html)
-* [Subdocuments](/docs/subdocs.html)
-* [Queries](/docs/queries.html)
-* [Validation](/docs/validation.html)
-* [Middleware](/docs/middleware.html)
-* [Populate](/docs/populate.html)
-* [Discriminators](/docs/discriminators.html)
-* [Plugins](/docs/plugins.html)
-* [Faster Mongoose Queries With Lean](/docs/tutorials/lean.html)
-* [Query Casting](/docs/tutorials/query_casting.html)
-* [findOneAndUpdate](/docs/tutorials/findoneandupdate.html)
-* [Getters and Setters](/docs/tutorials/getters-setters.html)
-* [Virtuals](/docs/tutorials/virtuals.html)
+* [Schemas](guide.html)
+* [SchemaTypes](schematypes.html)
+* [Connections](connections.html)
+* [Models](models.html)
+* [Documents](documents.html)
+* [Subdocuments](subdocs.html)
+* [Queries](queries.html)
+* [Validation](validation.html)
+* [Middleware](middleware.html)
+* [Populate](populate.html)
+* [Discriminators](discriminators.html)
+* [Plugins](plugins.html)
+* [Faster Mongoose Queries With Lean](tutorials/lean.html)
+* [Query Casting](tutorials/query_casting.html)
+* [findOneAndUpdate](tutorials/findoneandupdate.html)
+* [Getters and Setters](tutorials/getters-setters.html)
+* [Virtuals](tutorials/virtuals.html)
### Advanced Topics
-* [Working with Dates](/docs/tutorials/dates.html)
-* [Custom Casting For Built-in Types](/docs/tutorials/custom-casting.html)
-* [Custom SchemaTypes](/docs/customschematypes.html)
+* [Working with Dates](tutorials/dates.html)
+* [Custom Casting For Built-in Types](tutorials/custom-casting.html)
+* [Custom SchemaTypes](customschematypes.html)
### Integrations
-* [Promises](/docs/promises.html)
-* [AWS Lambda](/docs/lambda.html)
-* [Browser Library](/docs/browser.html)
-* [GeoJSON](/docs/geojson.html)
-* [Transactions](/docs/transactions.html)
-* [MongoDB Driver Deprecation Warnings](/docs/deprecations.html)
-* [Testing with Jest](/docs/jest.html)
-* [SSL Connections](/docs/tutorials/ssl.html)
+* [Promises](promises.html)
+* [AWS Lambda](lambda.html)
+* [Browser Library](browser.html)
+* [GeoJSON](geojson.html)
+* [Transactions](transactions.html)
+* [MongoDB Driver Deprecation Warnings](deprecations.html)
+* [Testing with Jest](jest.html)
+* [SSL Connections](tutorials/ssl.html)
### Migration Guides
-* [Mongoose 4.x to 5.x](/docs/migrating_to_5.html)
-* [Mongoose 3.x to 4.x](/docs/migration.html)
-
+* [Mongoose 4.x to 5.x](migrating_to_5.html)
+* [Mongoose 3.x to 4.x](migration.html)
diff --git a/docs/index.md b/docs/index.md
index 69fdf994253..1bec43b6fc4 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -46,7 +46,7 @@ db.once('open', function() {
Once our connection opens, our callback will be called. For brevity,
let's assume that all following code is within this callback.
-With Mongoose, everything is derived from a [Schema](/docs/guide.html).
+With Mongoose, everything is derived from a [Schema](guide.html).
Let's get a reference to it and define our kittens.
```javascript
@@ -55,7 +55,7 @@ const kittySchema = new mongoose.Schema({
});
```
-So far so good. We've got a schema with one property, `name`, which will be a `String`. The next step is compiling our schema into a [Model](/docs/models.html).
+So far so good. We've got a schema with one property, `name`, which will be a `String`. The next step is compiling our schema into a [Model](models.html).
```javascript
const Kitten = mongoose.model('Kitten', kittySchema);
@@ -94,7 +94,7 @@ fluffy.speak(); // "Meow name is fluffy"
```
We have talking kittens! But we still haven't saved anything to MongoDB.
-Each document can be saved to the database by calling its [save](/docs/api.html#model_Model-save) method. The first argument to the callback will be an error if any occurred.
+Each document can be saved to the database by calling its [save](api.html#model_Model-save) method. The first argument to the callback will be an error if any occurred.
```javascript
fluffy.save(function (err, fluffy) {
@@ -104,7 +104,7 @@ Each document can be saved to the database by calling its [save](/docs/api.html#
```
Say time goes by and we want to display all the kittens we've seen.
-We can access all of the kitten documents through our Kitten [model](/docs/models.html).
+We can access all of the kitten documents through our Kitten [model](models.html).
```javascript
Kitten.find(function (err, kittens) {
@@ -114,7 +114,7 @@ Kitten.find(function (err, kittens) {
```
We just logged all of the kittens in our db to the console.
-If we want to filter our kittens by name, Mongoose supports MongoDBs rich [querying](/docs/queries.html) syntax.
+If we want to filter our kittens by name, Mongoose supports MongoDBs rich [querying](queries.html) syntax.
```javascript
Kitten.find({ name: /^fluff/ }, callback);
diff --git a/docs/jest.md b/docs/jest.md
index 36e07845d45..108ca6efcd0 100644
--- a/docs/jest.md
+++ b/docs/jest.md
@@ -8,7 +8,7 @@ If you choose to delve into dangerous waters and test Mongoose apps with Jest, h
-If you are using Jest `<=26`, do **not** use Jest's default [`jsdom` test environment](https://jestjs.io/docs/en/configuration.html#testenvironment-string) when testing Mongoose apps, _unless_ you are explicitly testing an application that only uses [Mongoose's browser library](https://mongoosejs.com/docs/browser.html). In Jest `>=27`, ["node" is Jest's default `testEnvironment`](https://jestjs.io/ro/blog/2021/05/25/jest-27#flipping-defaults), so this is no longer an issue.
+If you are using Jest `<=26`, do **not** use Jest's default [`jsdom` test environment](https://jestjs.io/docs/en/configuration.html#testenvironment-string) when testing Mongoose apps, _unless_ you are explicitly testing an application that only uses [Mongoose's browser library](browser.html). In Jest `>=27`, ["node" is Jest's default `testEnvironment`](https://jestjs.io/ro/blog/2021/05/25/jest-27#flipping-defaults), so this is no longer an issue.
The `jsdom` test environment attempts to create a browser-like test
environment in Node.js, and it comes with numerous nasty surprises like a
@@ -81,4 +81,4 @@ course on Pluralsight has a great section on testing Mongoose apps with [Mocha](
-
\ No newline at end of file
+
diff --git a/docs/lambda.md b/docs/lambda.md
index 61c060828f8..0c94ec8ebc6 100644
--- a/docs/lambda.md
+++ b/docs/lambda.md
@@ -115,5 +115,5 @@ exports.connect = async function() {
*Want to learn how to check whether your favorite JavaScript frameworks, like [Express](http://expressjs.com/) or [React](https://reactjs.org/), work with async/await? Spoiler alert: neither Express nor React support async/await. Chapter 4 of Mastering Async/Await explains the basic principles for determining whether a framework supports async/await. [Get your copy!](http://asyncawait.net/?utm_source=mongoosejs&utm_campaign=lambda)*
-
+
diff --git a/docs/middleware.md b/docs/middleware.md
index be5bcec8075..dfc0c85467e 100644
--- a/docs/middleware.md
+++ b/docs/middleware.md
@@ -2,7 +2,7 @@
Middleware (also called pre and post *hooks*) are functions which are passed
control during execution of asynchronous functions. Middleware is specified
-on the schema level and is useful for writing [plugins](./plugins.html).
+on the schema level and is useful for writing [plugins](plugins.html).
- Types of Middleware
@@ -26,47 +26,47 @@ of middleware: document middleware, model middleware, aggregate middleware, and
Document middleware is supported for the following document functions.
In document middleware functions, `this` refers to the document.
-* [validate](/docs/api/document.html#document_Document-validate)
-* [save](/docs/api/model.html#model_Model-save)
-* [remove](/docs/api/model.html#model_Model-remove)
-* [updateOne](/docs/api/document.html#document_Document-updateOne)
-* [deleteOne](/docs/api/model.html#model_Model-deleteOne)
-* [init](/docs/api/document.html#document_Document-init) (note: init hooks are [synchronous](#synchronous))
+* [validate](api/document.html#document_Document-validate)
+* [save](api/model.html#model_Model-save)
+* [remove](api/model.html#model_Model-remove)
+* [updateOne](api/document.html#document_Document-updateOne)
+* [deleteOne](api/model.html#model_Model-deleteOne)
+* [init](api/document.html#document_Document-init) (note: init hooks are [synchronous](#synchronous))
Query middleware is supported for the following Model and Query functions.
In query middleware functions, `this` refers to the query.
-* [count](./api.html#query_Query-count)
-* [deleteMany](./api.html#query_Query-deleteMany)
-* [deleteOne](./api.html#query_Query-deleteOne)
-* [find](./api.html#query_Query-find)
-* [findOne](./api.html#query_Query-findOne)
-* [findOneAndDelete](./api.html#query_Query-findOneAndDelete)
-* [findOneAndRemove](./api.html#query_Query-findOneAndRemove)
-* [findOneAndUpdate](./api.html#query_Query-findOneAndUpdate)
-* [remove](./api.html#model_Model.remove)
-* [update](./api.html#query_Query-update)
-* [updateOne](./api.html#query_Query-updateOne)
-* [updateMany](./api.html#query_Query-updateMany)
+* [count](api.html#query_Query-count)
+* [deleteMany](api.html#query_Query-deleteMany)
+* [deleteOne](api.html#query_Query-deleteOne)
+* [find](api.html#query_Query-find)
+* [findOne](api.html#query_Query-findOne)
+* [findOneAndDelete](api.html#query_Query-findOneAndDelete)
+* [findOneAndRemove](api.html#query_Query-findOneAndRemove)
+* [findOneAndUpdate](api.html#query_Query-findOneAndUpdate)
+* [remove](api.html#model_Model.remove)
+* [update](api.html#query_Query-update)
+* [updateOne](api.html#query_Query-updateOne)
+* [updateMany](api.html#query_Query-updateMany)
Aggregate middleware is for `MyModel.aggregate()`. Aggregate middleware
executes when you call `exec()` on an aggregate object.
-In aggregate middleware, `this` refers to the [aggregation object](./api.html#model_Model.aggregate).
+In aggregate middleware, `this` refers to the [aggregation object](api.html#model_Model.aggregate).
-* [aggregate](./api.html#model_Model.aggregate)
+* [aggregate](api.html#model_Model.aggregate)
Model middleware is supported for the following model functions.
In model middleware functions, `this` refers to the model.
-* [insertMany](./api.html#model_Model.insertMany)
+* [insertMany](api.html#model_Model.insertMany)
All middleware types support pre and post hooks.
How pre and post hooks work is described in more detail below.
**Note:** If you specify `schema.pre('remove')`, Mongoose will register this
-middleware for [`doc.remove()`](./api.html#model_Model-remove) by default. If you
-want to your middleware to run on [`Query.remove()`](./api.html#query_Query-remove)
-use [`schema.pre('remove', { query: true, document: false }, fn)`](./api.html#schema_Schema-pre).
+middleware for [`doc.remove()`](api.html#model_Model-remove) by default. If you
+want to your middleware to run on [`Query.remove()`](api.html#query_Query-remove)
+use [`schema.pre('remove', { query: true, document: false }, fn)`](api.html#schema_Schema-pre).
**Note:** Unlike `schema.pre('remove')`, Mongoose registers `updateOne` and
`deleteOne` middleware on `Query#updateOne()` and `Query#deleteOne()` by default.
@@ -75,7 +75,7 @@ This means that both `doc.updateOne()` and `Model.updateOne()` trigger
`updateOne` or `deleteOne` middleware as document middleware, use
`schema.pre('updateOne', { document: true, query: false })`.
-**Note:** The [`create()`](./api.html#model_Model.create) function fires `save()` hooks.
+**Note:** The [`create()`](api.html#model_Model.create) function fires `save()` hooks.
@@ -178,7 +178,7 @@ error `err1` and then throw an error `err2`, mongoose will report `err1`.
-[post](/docs/api.html#schema_Schema-post) middleware are executed _after_
+[post](api.html#schema_Schema-post) middleware are executed _after_
the hooked method and all of its `pre` middleware have completed.
```javascript
@@ -221,7 +221,7 @@ schema.post('save', function(doc, next) {
-Calling `pre()` or `post()` after [compiling a model](/docs/models.html#compiling)
+Calling `pre()` or `post()` after [compiling a model](models.html#compiling)
does **not** work in Mongoose in general. For example, the below `pre('save')`
middleware will not fire.
@@ -238,8 +238,8 @@ schema.pre('save', () => console.log('Hello from pre save'));
new User({ name: 'test' }).save();
```
-This means that you must add all middleware and [plugins](/docs/plugins.html)
-**before** calling [`mongoose.model()`](/docs/api/mongoose.html#mongoose_Mongoose-model).
+This means that you must add all middleware and [plugins](plugins.html)
+**before** calling [`mongoose.model()`](api/mongoose.html#mongoose_Mongoose-model).
The below script will print out "Hello from pre save":
```javascript
@@ -256,7 +256,7 @@ new User({ name: 'test' }).save();
As a consequence, be careful about exporting Mongoose models from the same
file that you define your schema. If you choose to use this pattern, you
-must define [global plugins](/docs/api/mongoose.html#mongoose_Mongoose-plugin)
+must define [global plugins](api/mongoose.html#mongoose_Mongoose-plugin)
**before** calling `require()` on your model file.
```javascript
@@ -304,10 +304,10 @@ doc.remove();
Model.remove();
```
-You can pass options to [`Schema.pre()`](/docs/api.html#schema_Schema-pre)
-and [`Schema.post()`](/docs/api.html#schema_Schema-post) to switch whether
-Mongoose calls your `remove()` hook for [`Document.remove()`](/docs/api.html#model_Model-remove)
-or [`Model.remove()`](/docs/api.html#model_Model.remove). Note here that you need to set both `document` and `query` properties in the passed object:
+You can pass options to [`Schema.pre()`](api.html#schema_Schema-pre)
+and [`Schema.post()`](api.html#schema_Schema-post) to switch whether
+Mongoose calls your `remove()` hook for [`Document.remove()`](api.html#model_Model-remove)
+or [`Model.remove()`](api.html#model_Model.remove). Note here that you need to set both `document` and `query` properties in the passed object:
```javascript
// Only document middleware
@@ -372,7 +372,7 @@ schema.pre('findOneAndUpdate', async function() {
However, if you define `pre('updateOne')` document middleware,
`this` will be the document being updated. That's because `pre('updateOne')`
-document middleware hooks into [`Document#updateOne()`](/docs/api/document.html#document_Document-updateOne)
+document middleware hooks into [`Document#updateOne()`](api/document.html#document_Document-updateOne)
rather than `Query#updateOne()`.
```javascript
@@ -482,7 +482,7 @@ pipeline from middleware.
Certain Mongoose hooks are synchronous, which means they do **not** support
functions that return promises or receive a `next()` callback. Currently,
-only `init` hooks are synchronous, because the [`init()` function](./api.html#document_Document-init)
+only `init` hooks are synchronous, because the [`init()` function](api.html#document_Document-init)
is synchronous. Below is an example of using pre and post init hooks.
```javascript
@@ -500,4 +500,4 @@ rejections.
Next Up
Now that we've covered middleware, let's take a look at Mongoose's approach
-to faking JOINs with its query [population](/docs/populate.html) helper.
+to faking JOINs with its query [population](populate.html) helper.
diff --git a/docs/migrating_to_5.md b/docs/migrating_to_5.md
index 53048ab69e9..f3871363017 100644
--- a/docs/migrating_to_5.md
+++ b/docs/migrating_to_5.md
@@ -465,7 +465,7 @@ In Mongoose 5.x, the above code will correctly overwrite `'baseball'` with `{ $n
Mongoose 5.x uses version 3.x of the [MongoDB Node.js driver](http://npmjs.com/package/mongodb). MongoDB driver 3.x changed the format of
-the result of [`bulkWrite()` calls](/docs/api.html#model_Model.bulkWrite) so there is no longer a top-level `nInserted`, `nModified`, etc. property. The new result object structure is [described here](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#~BulkWriteOpResult).
+the result of [`bulkWrite()` calls](api.html#model_Model.bulkWrite) so there is no longer a top-level `nInserted`, `nModified`, etc. property. The new result object structure is [described here](http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#~BulkWriteOpResult).
```javascript
const Model = mongoose.model('Test', new Schema({ name: String }));
@@ -545,4 +545,4 @@ If this is blocking you from upgrading, you can set the `tlsInsecure` option to
```javascript
mongoose.connect(uri, { tlsInsecure: false }); // Opt out of additional SSL validation
-```
\ No newline at end of file
+```
diff --git a/docs/models.md b/docs/models.md
index 257ea18bdce..e4d2284013c 100644
--- a/docs/models.md
+++ b/docs/models.md
@@ -1,8 +1,8 @@
## Models
-[Models](./api.html#model-js) are fancy constructors compiled from
+[Models](api.html#model-js) are fancy constructors compiled from
`Schema` definitions. An instance of a model is called a
-[document](./documents.html). Models are responsible for creating and
+[document](documents.html). Models are responsible for creating and
reading documents from the underlying MongoDB database.
* [Compiling your first model](#compiling)
@@ -33,7 +33,7 @@ before calling `.model()`!
### Constructing Documents
-An instance of a model is called a [document](./documents.html). Creating
+An instance of a model is called a [document](documents.html). Creating
them and saving to the database is easy.
```javascript
@@ -75,13 +75,13 @@ const Tank = connection.model('Tank', yourSchema);
### Querying
-Finding documents is easy with Mongoose, which supports the [rich](http://www.mongodb.org/display/DOCS/Advanced+Queries) query syntax of MongoDB. Documents can be retreived using each `models` [find](./api.html#model_Model.find), [findById](./api.html#model_Model.findById), [findOne](./api.html#model_Model.findOne), or [where](./api.html#model_Model.where) static methods.
+Finding documents is easy with Mongoose, which supports the [rich](http://www.mongodb.org/display/DOCS/Advanced+Queries) query syntax of MongoDB. Documents can be retreived using each `models` [find](api.html#model_Model.find), [findById](api.html#model_Model.findById), [findOne](api.html#model_Model.findOne), or [where](api.html#model_Model.where) static methods.
```javascript
Tank.find({ size: 'small' }).where('createdDate').gt(oneYearAgo).exec(callback);
```
-See the chapter on [queries](./queries.html) for more details on how to use the [Query](./api.html#query-js) api.
+See the chapter on [queries](queries.html) for more details on how to use the [Query](api.html#query-js) api.
### Deleting
@@ -99,7 +99,7 @@ Tank.deleteOne({ size: 'large' }, function (err) {
Each `model` has its own `update` method for modifying documents in the
database without returning them to your application. See the
-[API](./api.html#model_Model.updateOne) docs for more detail.
+[API](api.html#model_Model.updateOne) docs for more detail.
```javascript
Tank.updateOne({ size: 'large' }, { name: 'T-90' }, function(err, res) {
@@ -109,7 +109,7 @@ Tank.updateOne({ size: 'large' }, { name: 'T-90' }, function(err, res) {
```
_If you want to update a single document in the db and return it to your
-application, use [findOneAndUpdate](./api.html#model_Model.findOneAndUpdate)
+application, use [findOneAndUpdate](api.html#model_Model.findOneAndUpdate)
instead._
### Change Streams
@@ -156,8 +156,8 @@ You can read more about [change streams in mongoose in this blog post](http://th
### Yet more
-The [API docs](./api.html#model_Model) cover many additional methods available like [count](./api.html#model_Model.count), [mapReduce](./api.html#model_Model.mapReduce), [aggregate](./api.html#model_Model.aggregate), and [more](./api.html#model_Model.findOneAndRemove).
+The [API docs](api.html#model_Model) cover many additional methods available like [count](api.html#model_Model.count), [mapReduce](api.html#model_Model.mapReduce), [aggregate](api.html#model_Model.aggregate), and [more](api.html#model_Model.findOneAndRemove).
### Next Up
-Now that we've covered `Models`, let's take a look at [Documents](/docs/documents.html).
\ No newline at end of file
+Now that we've covered `Models`, let's take a look at [Documents](documents.html).
diff --git a/docs/plugins.md b/docs/plugins.md
index 23a015b4ff7..e68f88270db 100644
--- a/docs/plugins.md
+++ b/docs/plugins.md
@@ -65,8 +65,8 @@ const Player = mongoose.model('Player', playerSchema);
-Because many plugins rely on [middleware](/docs/middleware.html), you should make sure to apply plugins **before**
-you call `mongoose.model()` or `conn.model()`. Otherwise, [any middleware the plugin registers won't get applied](/docs/middleware.html#defining).
+Because many plugins rely on [middleware](middleware.html), you should make sure to apply plugins **before**
+you call `mongoose.model()` or `conn.model()`. Otherwise, [any middleware the plugin registers won't get applied](middleware.html#defining).
```javascript
// loadedAt.js
@@ -101,8 +101,8 @@ gameSchema.plugin(loadedAtPlugin);
The Mongoose team maintains several plugins that add cool new features to
Mongoose. Here's a couple:
-* [mongoose-autopopulate](http://plugins.mongoosejs.io/plugins/autopopulate): Always [`populate()`](/docs/populate.html) certain fields in your Mongoose schemas.
-* [mongoose-lean-virtuals](http://plugins.mongoosejs.io/plugins/lean-virtuals): Attach virtuals to the results of Mongoose queries when using [`.lean()`](/docs/api.html#query_Query-lean).
+* [mongoose-autopopulate](http://plugins.mongoosejs.io/plugins/autopopulate): Always [`populate()`](populate.html) certain fields in your Mongoose schemas.
+* [mongoose-lean-virtuals](http://plugins.mongoosejs.io/plugins/lean-virtuals): Attach virtuals to the results of Mongoose queries when using [`.lean()`](api.html#query_Query-lean).
* [mongoose-cast-aggregation](https://www.npmjs.com/package/mongoose-cast-aggregation)
You can find a full list of officially supported plugins on [Mongoose's plugins search site](https://plugins.mongoosejs.io/).
diff --git a/docs/populate.md b/docs/populate.md
index c7c8bdbd8c5..b613104e3b2 100644
--- a/docs/populate.md
+++ b/docs/populate.md
@@ -25,7 +25,7 @@ const Story = mongoose.model('Story', storySchema);
const Person = mongoose.model('Person', personSchema);
```
-So far we've created two [Models](./models.html). Our `Person` model has
+So far we've created two [Models](models.html). Our `Person` model has
its `stories` field set to an array of `ObjectId`s. The `ref` option is
what tells Mongoose which model to use during population, in our case
the `Story` model. All `_id`s we store here must be document `_id`s from
@@ -105,7 +105,7 @@ is replaced with the mongoose document returned from the database by
performing a separate query before returning the results.
Arrays of refs work the same way. Just call the
-[populate](./api.html#query_Query-populate) method on the query and an
+[populate](api.html#query_Query-populate) method on the query and an
array of documents will be returned _in place_ of the original `_id`s.
@@ -137,7 +137,7 @@ story.populated('author'); // undefined
```
A common reason for checking whether a path is populated is getting the `author`
-id. However, for your convenience, Mongoose adds a [`_id` getter to ObjectId instances](/docs/api/mongoose.html#mongoose_Mongoose-set)
+id. However, for your convenience, Mongoose adds a [`_id` getter to ObjectId instances](api/mongoose.html#mongoose_Mongoose-set)
so you can use `story.author._id` regardless of whether `author` is populated.
```javascript
@@ -184,7 +184,7 @@ story.authors; // `[]`
What if we only want a few specific fields returned for the populated
documents? This can be accomplished by passing the usual
-[field name syntax](./api.html#query_Query-select) as the second argument
+[field name syntax](api.html#query_Query-select) as the second argument
to the populate method:
```javascript
@@ -367,10 +367,10 @@ Story.
```
The documents returned from
-[query population](./api.html#query_Query-populate) become fully
+[query population](api.html#query_Query-populate) become fully
functional, `remove`able, `save`able documents unless the
-[lean](./api.html#query_Query-lean) option is specified. Do not confuse
-them with [sub docs](./subdocs.html). Take caution when calling its
+[lean](api.html#query_Query-lean) option is specified. Do not confuse
+them with [sub docs](subdocs.html). Take caution when calling its
remove method because you'll be removing it from the database, not just
the array.
@@ -378,8 +378,8 @@ the array.
If you have an existing mongoose document and want to populate some of its
paths, you can use the
-[Document#populate()](./api.html#document_Document-populate) method.
-Just make sure you call [`Document#execPopulate()`](/docs/api/document.html#document_Document-execPopulate)
+[Document#populate()](api.html#document_Document-populate) method.
+Just make sure you call [`Document#execPopulate()`](api/document.html#document_Document-execPopulate)
to execute the `populate()`.
```javascript
@@ -406,8 +406,8 @@ person.populated('fans'); // Array of ObjectIds
If we have one or many mongoose documents or even plain objects
-(_like [mapReduce](./api.html#model_Model.mapReduce) output_), we may
-populate them using the [Model.populate()](./api.html#model_Model.populate)
+(_like [mapReduce](api.html#model_Model.mapReduce) output_), we may
+populate them using the [Model.populate()](api.html#model_Model.populate)
method. This is what `Document#populate()`
and `Query#populate()` use to populate documents.
@@ -474,7 +474,7 @@ This is known as a "cross-database populate," because it enables you to
populate across MongoDB databases and even across MongoDB instances.
If you don't have access to the model instance when defining your `eventSchema`,
-you can also pass [the model instance as an option to `populate()`](/docs/api/model.html#model_Model.populate).
+you can also pass [the model instance as an option to `populate()`](api/model.html#model_Model.populate).
```javascript
const events = await Event.
@@ -709,7 +709,7 @@ doc.numMembers; // 2
-[Maps](/docs/schematypes.html#maps) are a type that represents an object with arbitrary
+[Maps](schematypes.html#maps) are a type that represents an object with arbitrary
string keys. For example, in the below schema, `members` is a map from strings to ObjectIds.
```javascript
@@ -813,4 +813,4 @@ MySchema.post('save', function(doc, next) {
### Next Up
-Now that we've covered `populate()`, let's take a look at [discriminators](/docs/discriminators.html).
+Now that we've covered `populate()`, let's take a look at [discriminators](discriminators.html).
diff --git a/docs/promises.md b/docs/promises.md
index 562626890a3..9f52f32b13b 100644
--- a/docs/promises.md
+++ b/docs/promises.md
@@ -7,7 +7,7 @@ This means that you can do things like `MyModel.findOne({}).then()` and
`await MyModel.findOne({}).exec()` if you're using
[async/await](http://thecodebarbarian.com/80-20-guide-to-async-await-in-node.js.html).
-You can find the return type of specific operations [in the api docs](https://mongoosejs.com/docs/api.html)
+You can find the return type of specific operations [in the api docs](api.html)
You can also read more about [promises in Mongoose](https://masteringjs.io/tutorials/mongoose/promise).
```javascript
@@ -71,5 +71,5 @@ ES6-style promise constructor and mongoose will use it.
-
-
\ No newline at end of file
+
+
diff --git a/docs/queries.md b/docs/queries.md
index 501fe37068f..c6c158ebded 100644
--- a/docs/queries.md
+++ b/docs/queries.md
@@ -1,25 +1,25 @@
## Queries
-Mongoose [models](./models.html) provide several static helper functions
+Mongoose [models](models.html) provide several static helper functions
for [CRUD operations](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete).
Each of these functions returns a
[mongoose `Query` object](http://mongoosejs.com/docs/api.html#Query).
-- [`Model.deleteMany()`](/docs/api.html#model_Model.deleteMany)
-- [`Model.deleteOne()`](/docs/api.html#model_Model.deleteOne)
-- [`Model.find()`](/docs/api.html#model_Model.find)
-- [`Model.findById()`](/docs/api.html#model_Model.findById)
-- [`Model.findByIdAndDelete()`](/docs/api.html#model_Model.findByIdAndDelete)
-- [`Model.findByIdAndRemove()`](/docs/api.html#model_Model.findByIdAndRemove)
-- [`Model.findByIdAndUpdate()`](/docs/api.html#model_Model.findByIdAndUpdate)
-- [`Model.findOne()`](/docs/api.html#model_Model.findOne)
-- [`Model.findOneAndDelete()`](/docs/api.html#model_Model.findOneAndDelete)
-- [`Model.findOneAndRemove()`](/docs/api.html#model_Model.findOneAndRemove)
-- [`Model.findOneAndReplace()`](/docs/api.html#model_Model.findOneAndReplace)
-- [`Model.findOneAndUpdate()`](/docs/api.html#model_Model.findOneAndUpdate)
-- [`Model.replaceOne()`](/docs/api.html#model_Model.replaceOne)
-- [`Model.updateMany()`](/docs/api.html#model_Model.updateMany)
-- [`Model.updateOne()`](/docs/api.html#model_Model.updateOne)
+- [`Model.deleteMany()`](api.html#model_Model.deleteMany)
+- [`Model.deleteOne()`](api.html#model_Model.deleteOne)
+- [`Model.find()`](api.html#model_Model.find)
+- [`Model.findById()`](api.html#model_Model.findById)
+- [`Model.findByIdAndDelete()`](api.html#model_Model.findByIdAndDelete)
+- [`Model.findByIdAndRemove()`](api.html#model_Model.findByIdAndRemove)
+- [`Model.findByIdAndUpdate()`](api.html#model_Model.findByIdAndUpdate)
+- [`Model.findOne()`](api.html#model_Model.findOne)
+- [`Model.findOneAndDelete()`](api.html#model_Model.findOneAndDelete)
+- [`Model.findOneAndRemove()`](api.html#model_Model.findOneAndRemove)
+- [`Model.findOneAndReplace()`](api.html#model_Model.findOneAndReplace)
+- [`Model.findOneAndUpdate()`](api.html#model_Model.findOneAndUpdate)
+- [`Model.replaceOne()`](api.html#model_Model.replaceOne)
+- [`Model.updateMany()`](api.html#model_Model.updateMany)
+- [`Model.updateOne()`](api.html#model_Model.updateOne)
A mongoose query can be executed in one of two ways. First, if you
pass in a `callback` function, Mongoose will execute the query asynchronously
@@ -55,7 +55,7 @@ Mongoose executed the query and passed the results to `callback`. All callbacks
`callback(error, result)`. If an error occurs executing the query, the `error` parameter will contain an error document, and `result`
will be null. If the query is successful, the `error` parameter will be null, and the `result` will be populated with the results of the query.
-Anywhere a callback is passed to a query in Mongoose, the callback follows the pattern `callback(error, results)`. What `results` is depends on the operation: For `findOne()` it is a [potentially-null single document](./api.html#model_Model.findOne), `find()` a [list of documents](./api.html#model_Model.find), `count()` [the number of documents](./api.html#model_Model.count), `update()` the [number of documents affected](./api.html#model_Model.update), etc. The [API docs for Models](./api.html#model-js) provide more detail on what is passed to the callbacks.
+Anywhere a callback is passed to a query in Mongoose, the callback follows the pattern `callback(error, results)`. What `results` is depends on the operation: For `findOne()` it is a [potentially-null single document](api.html#model_Model.findOne), `find()` a [list of documents](api.html#model_Model.find), `count()` [the number of documents](api.html#model_Model.count), `update()` the [number of documents affected](api.html#model_Model.update), etc. The [API docs for Models](api.html#model-js) provide more detail on what is passed to the callbacks.
Now let's look at what happens when no `callback` is passed:
@@ -75,7 +75,7 @@ query.exec(function (err, person) {
});
```
-In the above code, the `query` variable is of type [Query](./api.html#query-js).
+In the above code, the `query` variable is of type [Query](api.html#query-js).
A `Query` enables you to build up a query using chaining syntax, rather than specifying a JSON object.
The below 2 examples are equivalent.
@@ -105,7 +105,7 @@ Person.
exec(callback);
```
-A full list of [Query helper functions can be found in the API docs](./api.html#query-js).
+A full list of [Query helper functions can be found in the API docs](api.html#query-js).