Skip to content

Commit

Permalink
Merge remote-tracking branch 'automattic/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens von Pilgrim committed Apr 26, 2023
2 parents f97147f + d6a7611 commit 37454e9
Show file tree
Hide file tree
Showing 86 changed files with 2,054 additions and 1,504 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
'test/files/*',
'benchmarks',
'*.min.js',
'docs/js/native.js'
'**/docs/js/native.js'
],
overrides: [
{
Expand Down Expand Up @@ -77,7 +77,7 @@ module.exports = {
},
{
files: [
'docs/js/**/*.js'
'**/docs/js/**/*.js'
],
env: {
node: false,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-20.04
name: Benchmark TypeScript Types
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
with:
fetch-depth: 0
- name: Setup node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
runs-on: ubuntu-20.04
name: Test Generating Docs
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
- run: git fetch --depth=1 --tags # download all tags for documentation

- name: Setup node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: stale
uses: actions/stale@v7
uses: actions/stale@v8
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days'
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
name: Lint JS-Files
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0

- name: Setup node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
MONGOMS_VERSION: ${{ matrix.mongodb }}
MONGOMS_PREFER_GLOBAL_PATH: 1
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0

- name: Setup node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
MONGOMS_VERSION: 6.0.4
MONGOMS_PREFER_GLOBAL_PATH: 1
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
- name: Setup node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
Expand All @@ -118,7 +118,7 @@ jobs:
runs-on: ubuntu-latest
name: Replica Set tests
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
- name: Setup node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
Expand All @@ -135,6 +135,6 @@ jobs:
contents: read
steps:
- name: Check out repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
- name: Dependency review
uses: actions/dependency-review-action@v3
2 changes: 1 addition & 1 deletion .github/workflows/tidelift-alignment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
if: github.repository == 'Automattic/mongoose'
steps:
- name: Checkout
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
- name: Setup node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
name: Lint TS-Files
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0

- name: Setup node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
Expand All @@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
name: Test Typescript Types
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0

- name: Setup node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ docs/*.html
docs/tutorials/*.html
docs/typescript/*.html
docs/api/*.html
# the below excludes things like "0test.x" too, but gitignore does not have something like js regex "[0-9]+", so this is the best for future versions
docs/[0-9]*.x/
index.html

# Local Netlify folder
Expand All @@ -64,4 +66,4 @@ mongoose-*.tgz
examples/ecommerce-netlify-functions/.netlify/state.json

notes.md
list.out
list.out
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
7.0.5 / 2023-04-24
==================
* fix(schema): correctly handle uuids with populate() #13317 #13267
* fix(schema): add clusteredIndex to schema options #13286 [jakesjews](https://github.com/jakesjews)
* fix(document): use collection.findOne() for saving docs with no changes to avoid firing findOne middleware #13298
* types(schema): avoid circular constraint in TSchemaOptions with --incremental by deferring ResolveSchemaOptions<> #13291 #13129
* docs(subdocs): fix mention of subdocument ".remove" function #13312 [hasezoey](https://github.com/hasezoey)
* docs: add mongoose.Promise removal to migrating to 7 guide #13295
* docs: updated formatting of Error Handling section to better highlight the two kinds of possible errors #13279 [Ankit-Mandal](https://github.com/Ankit-Mandal)
* docs: fix broken link #13301 #13281

7.0.4 / 2023-04-17
==================
* fix(schema): fix dangling reference to virtual in tree after removeVirtual() #13255 #13085
* fix(query): cast query filters on `findOneAndUpdate()` #13220 #13219 [dermasmid](https://github.com/dermasmid)
* types(model): aligned watch() type for mongodb 4.6.0 #13208 #13206
* docs: fix async function anchors #13226 [hasezoey](https://github.com/hasezoey)
* docs: fix schema syntax in exemple #13262 [c-marc](https://github.com/c-marc)
* docs: rework scripts to allow easier setting of current and past versions #13222
#13148 [hasezoey](https://github.com/hasezoey)

6.10.5 / 2023-04-06
===================
* perf(document): avoid unnecessary loops, conditionals, string manipulation on Document.prototype.get() for 10x speedup on top-level properties #12953
* fix(model): execute valid write operations if calling bulkWrite() with ordered: false #13218 #13176
* fix(array): pass-through all parameters #13202 #13201 [hasezoey](https://github.com/hasezoey)
* fix: improve error message when sorting by empty string #13249 #10182
* docs: add version support and check version docs #13251 #13193

5.13.17 / 2023-04-04
====================
* fix: backport fix for array filters handling $or and $and #13195 #13192 #10696 [raj-goguardian](https://github.com/raj-goguardian)
* fix: update the isIndexEqual function to take into account non-text indexes when checking compound indexes that include both text and non-text indexes #13138 #13136 [rdeavila94](https://github.com/rdeavila94)

7.0.3 / 2023-03-23
==================
* fix(query): avoid executing transforms if query wasn't executed #13185 #13165
Expand Down
108 changes: 70 additions & 38 deletions benchmarks/get.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,72 @@
'use strict';

const get = require('../lib/helpers/get');

let obj;

// Single string
obj = {};

let start = Date.now();
for (let i = 0; i < 10000000; ++i) {
get(obj, 'test', null);
}
console.log('Single string', Date.now() - start);

// Array of length 1
obj = {};
start = Date.now();
let arr = ['test'];
for (let i = 0; i < 10000000; ++i) {
get(obj, arr, null);
}
console.log('Array of length 1', Date.now() - start);

// String with dots
obj = { a: { b: 1 } };
start = Date.now();
for (let i = 0; i < 10000000; ++i) {
get(obj, 'a.b', null);
}
console.log('String with dots', Date.now() - start);

// Multi element array
obj = { a: { b: 1 } };
start = Date.now();
arr = ['a', 'b'];
for (let i = 0; i < 10000000; ++i) {
get(obj, arr, null);
}
console.log('Multi element array', Date.now() - start);
const mongoose = require('../');

run().catch(err => {
console.error(err);
process.exit(-1);
});

async function run() {
const schema = new mongoose.Schema({
field1: {type: String, default: Math.random().toString(36).slice(2, 16)},
field2: {type: String, default: Math.random().toString(36).slice(2, 16)},
field3: {type: String, default: Math.random().toString(36).slice(2, 16)},
field4: {type: String, default: Math.random().toString(36).slice(2, 16)},
field5: {type: String, default: Math.random().toString(36).slice(2, 16)},
field6: {type: String, default: Math.random().toString(36).slice(2, 16)},
field7: {type: String, default: Math.random().toString(36).slice(2, 16)},
field8: {type: String, default: Math.random().toString(36).slice(2, 16)},
}, { versionKey: false });
const TestModel = mongoose.model('Test', schema);

let tests = [];
for (let i = 0; i < 10000; i++) {
tests.push(new TestModel());
}

let loopStart = Date.now();

// run loop with mongoose objects
for (let k = 0; k < 100; k++) {
for (let test of tests) {
test.field1;
test.field2;
test.field3;
test.field4;
test.field5;
test.field6;
test.field7;
test.field8;
}
}

const results = {
'Model loop ms': Date.now() - loopStart
};

const plainTests = [];
for (let test of tests) {
plainTests.push(test.toObject());
}

loopStart = Date.now();

// run loop with plain objects
for (let k = 0; k < 100; k++) {
for (let test of plainTests) {
test.field1;
test.field2;
test.field3;
test.field4;
test.field5;
test.field6;
test.field7;
test.field8;
}
}

results['POJO loop ms'] = Date.now() - loopStart;

console.log(JSON.stringify(results, null, ' '));
}
20 changes: 10 additions & 10 deletions docs/api_split.pug
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
extends layout

append style
link(rel="stylesheet", href="/docs/css/api.css")
script(src="/docs/js/api-bold-current-nav.js")
script(src="/docs/js/convert-old-anchorid.js")
link(rel="stylesheet", href=`${versions.versionedPath}/docs/css/api.css`)
script(src=`${versions.versionedPath}/docs/js/api-bold-current-nav.js`)
script(src=`${versions.versionedPath}/docs/js/convert-old-anchorid.js`)

block content
<a class="edit-docs-link" href="#{editLink}" target="_blank">
<img src="/docs/images/pencil.svg" />
<img src="#{versions.versionedPath}/docs/images/pencil.svg" />
</a>
h1 #{name}
h1 #{title}

include includes/native

div.api-nav
div.api-nav-content
each item in docs
- if (!item.hideFromNav || item.name === name)
div.nav-item(id='nav-' + item.name)
- if (item.name === name)
- if (!item.hideFromNav || item.title === title)
div.nav-item(id='nav-' + item.title)
- if (item.title === title)
div.nav-item-title(style="font-weight: bold")
a(href=item.fileName + '.html')
| #{item.name}
| #{item.title}
ul.nav-item-sub
each prop in item.props
li
Expand All @@ -30,7 +30,7 @@ block content
- else
div.nav-item-title
a(href=item.fileName + '.html')
| #{item.name}
| #{item.title}

div.api-content
ul
Expand Down
34 changes: 34 additions & 0 deletions docs/check-version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# How to Check Your Mongoose Version

To check what version of Mongoose you are using in Node.js, print out the [`mongoose.version` property](./api/mongoose.html#Mongoose.prototype.version) as follows.

```javascript
const mongoose = require('mongoose');

console.log(mongoose.version); // '7.x.x'
```

We recommend printing the Mongoose version from Node.js, because that better handles cases where you have multiple versions of Mongoose installed.
You can also execute the above logic from your terminal using Node.js' `-e` flag as follows.

```
# Prints current Mongoose version, e.g. 7.0.3
node -e "console.log(require('mongoose').version)"
```

## Using `npm list`

You can also [get the installed version of the Mongoose npm package](https://masteringjs.io/tutorials/npm/version) using `npm list`.

```
$ npm list mongoose
test@ /path/to/test
└── mongoose@7.0.3
```

`npm list` is helpful because it can identify if you have multiple versions of Mongoose installed.

Other package managers also support similar functions:

- [`yarn list --pattern "mongoose"`](https://classic.yarnpkg.com/lang/en/docs/cli/list/)
- [`pnpm list "mongoose"`](https://pnpm.io/cli/list)
4 changes: 2 additions & 2 deletions docs/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ await Model.createCollection();

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

- Error on initial connection. If initial connection fails, Mongoose will emit an 'error' event and the promise `mongoose.connect()` returns will reject. However, Mongoose will **not** automatically try to reconnect.
- Error after initial connection was established. Mongoose will attempt to reconnect, and it will emit an 'error' event.
- **Error on initial connection**: If initial connection fails, Mongoose will emit an 'error' event and the promise `mongoose.connect()` returns will reject. However, Mongoose will **not** automatically try to reconnect.
- **Error after initial connection was established**: Mongoose will attempt to reconnect, and it will emit an 'error' event.

To handle initial connection errors, you should use `.catch()` or `try/catch` with async/await.

Expand Down
Loading

0 comments on commit 37454e9

Please sign in to comment.