Skip to content

Commit 687dfe6

Browse files
authored
Merge pull request Automattic#12768 from Automattic/6.8
6.8
2 parents 1717e16 + c561459 commit 687dfe6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+966
-498
lines changed

.github/workflows/test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ jobs:
8686
with:
8787
name: coverage
8888
path: coverage
89+
90+
test-deno:
91+
runs-on: ubuntu-20.04
92+
name: Deno tests
93+
steps:
94+
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
95+
- name: Setup
96+
run: |
97+
wget -q https://downloads.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-6.0.0.tgz
98+
tar xf mongodb-linux-x86_64-ubuntu2004-6.0.0.tgz
99+
mkdir -p ./data/db/27017 ./data/db/27000
100+
printf "\ntimeout: 8000" >> ./.mocharc.yml
101+
./mongodb-linux-x86_64-ubuntu2004-6.0.0/bin/mongod --setParameter ttlMonitorSleepSecs=1 --fork --dbpath ./data/db/27017 --syslog --port 27017
102+
sleep 2
103+
mongod --version
104+
echo `pwd`/mongodb-linux-x86_64-ubuntu2004-6.0.0/bin >> $GITHUB_PATH
105+
- name: Setup node
106+
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # v3.4.1
107+
with:
108+
node-version: 16
109+
- name: Setup Deno
110+
uses: denoland/setup-deno@v1
111+
with:
112+
deno-version: v1.28.x
113+
- run: deno --version
114+
- run: npm install
115+
- name: Run Deno tests
116+
run: npm run test-deno
89117

90118
test-replica-sets:
91119
needs:

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ If you have a question about Mongoose (not a bug report) please post it to eithe
4949

5050
### Documentation
5151

52-
To contribute to the [API documentation](http://mongoosejs.com/docs/api.html) just make your changes to the inline documentation of the appropriate [source code](https://github.com/Automattic/mongoose/tree/master/lib) in the master branch and submit a [pull request](https://help.github.com/articles/using-pull-requests/). You might also use the github [Edit](https://github.com/blog/844-forking-with-the-edit-button) button.
52+
To contribute to the [API documentation](http://mongoosejs.com/docs/api/mongoose.html) just make your changes to the inline documentation of the appropriate [source code](https://github.com/Automattic/mongoose/tree/master/lib) in the master branch and submit a [pull request](https://help.github.com/articles/using-pull-requests/). You might also use the github [Edit](https://github.com/blog/844-forking-with-the-edit-button) button.
5353

5454
To contribute to the [guide](http://mongoosejs.com/docs/guide.html) or [quick start](http://mongoosejs.com/docs/index.html) docs, make your changes to the appropriate `.pug` / `.md` files in the [docs](https://github.com/Automattic/mongoose/tree/master/docs) directory of the master branch and submit a pull request. Again, the [Edit](https://github.com/blog/844-forking-with-the-edit-button) button might work for you here.
5555

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Mongoose
22

3-
Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed to work in an asynchronous environment. Mongoose supports both promises and callbacks.
3+
Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed to work in an asynchronous environment. Mongoose supports [Node.js](https://nodejs.org/en/) and [Deno](https://deno.land/) (alpha).
44

5-
[![Slack Status](https://img.shields.io/badge/slack-mongoosejsteam-34D058.svg?logo=slack )](https://mongoosejsteam.slack.com)
65
[![Build Status](https://github.com/Automattic/mongoose/workflows/Test/badge.svg)](https://github.com/Automattic/mongoose)
76
[![NPM version](https://badge.fury.io/js/mongoose.svg)](http://badge.fury.io/js/mongoose)
7+
[![Deno version](https://deno.land/badge/mongoose/version)](https://deno.land/x/mongoose)
8+
[![Deno popularity](https://deno.land/badge/mongoose/popularity)](https://deno.land/x/mongoose)
89

910
[![npm](https://nodei.co/npm/mongoose.png)](https://www.npmjs.com/package/mongoose)
1011

@@ -45,6 +46,8 @@ First install [Node.js](http://nodejs.org/) and [MongoDB](https://www.mongodb.or
4546
$ npm install mongoose
4647
```
4748

49+
Mongoose 6.8.0 also includes alpha support for [Deno](https://deno.land/).
50+
4851
## Importing
4952

5053
```javascript
@@ -55,6 +58,24 @@ const mongoose = require('mongoose');
5558
import mongoose from 'mongoose';
5659
```
5760

61+
Or, using [Deno's `createRequire()` for CommonJS support](https://deno.land/std@0.113.0/node/README.md?source=#commonjs-modules-loading) as follows.
62+
63+
```javascript
64+
import { createRequire } from "https://deno.land/std/node/module.ts";
65+
const require = createRequire(import.meta.url);
66+
67+
const mongoose = require('mongoose');
68+
69+
mongoose.connect('mongodb://localhost:27017/test')
70+
.then(() => console.log('Connected!'));
71+
```
72+
73+
You can then run the above script using the following.
74+
75+
```
76+
deno run --allow-net --allow-read --allow-sys --allow-env mongoose-test.js
77+
```
78+
5879
## Mongoose for Enterprise
5980
6081
Available as part of the Tidelift Subscription
@@ -98,9 +119,9 @@ const BlogPost = new Schema({
98119
Aside from defining the structure of your documents and the types of data you're storing, a Schema handles the definition of:
99120

100121
* [Validators](http://mongoosejs.com/docs/validation.html) (async and sync)
101-
* [Defaults](http://mongoosejs.com/docs/api.html#schematype_SchemaType-default)
102-
* [Getters](http://mongoosejs.com/docs/api.html#schematype_SchemaType-get)
103-
* [Setters](http://mongoosejs.com/docs/api.html#schematype_SchemaType-set)
122+
* [Defaults](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-default)
123+
* [Getters](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-get)
124+
* [Setters](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-set)
104125
* [Indexes](http://mongoosejs.com/docs/guide.html#indexes)
105126
* [Middleware](http://mongoosejs.com/docs/middleware.html)
106127
* [Methods](http://mongoosejs.com/docs/guide.html#methods) definition
@@ -316,7 +337,7 @@ return a cursor.
316337
317338
## API Docs
318339
319-
Find the API docs [here](http://mongoosejs.com/docs/api.html), generated using [dox](https://github.com/tj/dox)
340+
Find the API docs [here](http://mongoosejs.com/docs/api/mongoose.html), generated using [dox](https://github.com/tj/dox)
320341
and [acquit](https://github.com/vkarpov15/acquit).
321342
322343
## Related Projects

docs/async-await.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async function awaitUpdate() {
6262
}
6363
```
6464

65-
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.
65+
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.
6666

6767
### Async Functions
6868

@@ -147,5 +147,5 @@ async function observeQuery() {
147147
```
148148

149149
You are most likely to accidentally re-execute queries in this way when mixing callbacks with async/await.
150-
This is never necessary and should be avoided.
151-
If you need a Query to return a fully-fledged promise instead of a thenable, you can use [Query#exec()](api/query.html#query_Query-exec).
150+
This is never necessary and should be avoided.
151+
If you need a Query to return a fully-fledged promise instead of a [thenable](https://masteringjs.io/tutorials/fundamentals/thenable), you can use [Query#exec()](api/query.html#query_Query-exec).

docs/connections.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ connection may emit.
235235
* `connecting`: Emitted when Mongoose starts making its initial connection to the MongoDB server
236236
* `connected`: Emitted when Mongoose successfully makes its initial connection to the MongoDB server, or when Mongoose reconnects after losing connectivity. May be emitted multiple times if Mongoose loses connectivity.
237237
* `open`: Emitted after `'connected'` and `onOpen` is executed on all of this connection's models.
238-
* `disconnecting`: Your app called [`Connection#close()`](api.html#connection_Connection-close) to disconnect from MongoDB
238+
* `disconnecting`: Your app called [`Connection#close()`](api/connection.html#connection_Connection-close) to disconnect from MongoDB
239239
* `disconnected`: Emitted when Mongoose lost connection to the MongoDB server. This event may be due to your code explicitly closing the connection, the database server crashing, or network connectivity issues.
240-
* `close`: Emitted after [`Connection#close()`](api.html#connection_Connection-close) successfully closes the connection. If you call `conn.close()`, you'll get both a 'disconnected' event and a 'close' event.
240+
* `close`: Emitted after [`Connection#close()`](api/connection.html#connection_Connection-close) successfully closes the connection. If you call `conn.close()`, you'll get both a 'disconnected' event and a 'close' event.
241241
* `reconnected`: Emitted if Mongoose lost connectivity to MongoDB and successfully reconnected. Mongoose attempts to [automatically reconnect](https://thecodebarbarian.com/managing-connections-with-the-mongodb-node-driver.html) when it loses connection to the database.
242242
* `error`: Emitted if an error occurs on a connection, like a `parseError` due to malformed data or a payload larger than [16MB](https://docs.mongodb.com/manual/reference/limits/#BSON-Document-Size).
243243
* `fullsetup`: Emitted when you're connecting to a replica set and Mongoose has successfully connected to the primary and at least one secondary.
@@ -379,8 +379,8 @@ The `mongoose.createConnection()` function takes the same arguments as
379379
const conn = mongoose.createConnection('mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]', options);
380380
```
381381

382-
This [connection](api.html#connection_Connection) object is then used to
383-
create and retrieve [models](api.html#model_Model). Models are
382+
This [connection](api/connection.html#connection_Connection) object is then used to
383+
create and retrieve [models](api/model.html#model_Model). Models are
384384
**always** scoped to a single connection.
385385

386386
```javascript

docs/deprecations.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ deleteMany, or bulkWrite instead.
2828
```
2929

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

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

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

49-
Like `remove()`, the [`update()` function](api.html#model_Model-update) is deprecated in favor
50-
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
51-
`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](api.html#model_Model-update).
49+
Like `remove()`, the [`update()` function](model.html#model_Model-update) is deprecated in favor
50+
of the more explicit [`updateOne()`](model.html#model_Model-updateOne), [`updateMany()`](model.html#model_Model-updateMany), and [`replaceOne()`](model.html#model_Model-replaceOne) functions. You should replace
51+
`update()` with `updateOne()`, unless you use the [`multi` or `overwrite` options](model.html#model_Model-update).
5252

5353
```
5454
collection.update is deprecated. Use updateOne, updateMany, or bulkWrite

docs/documents.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ to documents as stored in MongoDB. Each document is an instance of its
1515

1616
<h2 id="documents-vs-models"><a href="#documents-vs-models">Documents vs Models</a></h2>
1717

18-
[Document](api.html#Document) and [Model](api.html#Model) are distinct
18+
[Document](api/document.html#Document) and [Model](api/model.html#Model) are distinct
1919
classes in Mongoose. The Model class is a subclass of the Document class.
20-
When you use the [Model constructor](api.html#Model), you create a
20+
When you use the [Model constructor](api/model.html#Model), you create a
2121
new document.
2222

2323
```javascript
@@ -35,7 +35,7 @@ going through a model.
3535

3636
<h2 id="retrieving"><a href="#retrieving">Retrieving</a></h2>
3737

38-
When you load documents from MongoDB using model functions like [`findOne()`](api.html#model_Model-findOne),
38+
When you load documents from MongoDB using model functions like [`findOne()`](api/model.html#model_Model-findOne),
3939
you get a Mongoose document back.
4040

4141
```javascript
@@ -83,7 +83,7 @@ await doc.save(); // Throws DocumentNotFoundError
8383

8484
<h2 id="updating-using-queries"><a href="#updating-using-queries">Updating Using Queries</a></h2>
8585

86-
The [`save()`](api.html#model_Model-save) function is generally the right
86+
The [`save()`](api/model.html#model_Model-save) function is generally the right
8787
way to update a document with Mongoose. With `save()`, you get full
8888
[validation](validation.html) and [middleware](middleware.html).
8989

@@ -104,7 +104,7 @@ first query for the document and then `save()` it._
104104

105105
Documents are casted and validated before they are saved. Mongoose first casts
106106
values to the specified type and then validates them. Internally, Mongoose
107-
calls the document's [`validate()` method](api.html#document_Document-validate)
107+
calls the document's [`validate()` method](api/document.html#document_Document-validate)
108108
before saving.
109109

110110
```javascript

docs/faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ is undefined on the underlying [POJO](guide.html#minimize).
132132

133133
<hr id="arrow-functions" />
134134

135-
<a class="anchor" href="#arrow-functions">**Q**</a>. 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.
135+
<a class="anchor" href="#arrow-functions">**Q**</a>. I'm using an arrow function for a [virtual](guide.html#virtuals), [middleware](middleware.html), [getter](api/schematype.html#schematype_SchemaType-get)/[setter](api/schematype.html#schematype_SchemaType-set), or [method](guide.html#methods) and the value of `this` is wrong.
136136

137137
**A**. Arrow functions [handle the `this` keyword much differently than conventional functions](https://masteringjs.io/tutorials/fundamentals/arrow#why-not-arrow-functions).
138138
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.
@@ -245,7 +245,7 @@ mongoose.set('debug', { color: false })
245245
mongoose.set('debug', { shell: true })
246246
```
247247

248-
For more debugging options (streams, callbacks), see the ['debug' option under `.set()`](api.html#mongoose_Mongoose-set).
248+
For more debugging options (streams, callbacks), see the ['debug' option under `.set()`](api/mongoose.html#mongoose_Mongoose-set).
249249

250250
<hr id="callback_never_executes" />
251251

docs/geojson.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ a polygon representing the state of Colorado using
127127
[require:geojson.*driver query]
128128
```
129129

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

133133
```javascript

0 commit comments

Comments
 (0)