Skip to content

Commit 9eaf5e8

Browse files
authored
Merge branch '8.10' into vkarpov15/Automatticgh-15201
2 parents 9444bfe + 0722e8f commit 9eaf5e8

Some content is hidden

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

57 files changed

+1938
-111
lines changed

.eslintrc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module.exports = {
1414
'**/docs/js/native.js',
1515
'!.*',
1616
'node_modules',
17-
'.git'
17+
'.git',
18+
'data'
1819
],
1920
overrides: [
2021
{
@@ -104,7 +105,7 @@ module.exports = {
104105
// 'markdown'
105106
],
106107
parserOptions: {
107-
ecmaVersion: 2020
108+
ecmaVersion: 2022
108109
},
109110
env: {
110111
node: true,

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
fetch-depth: 0
2828
- name: Setup node
29-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
29+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
3030
with:
3131
node-version: 22
3232

.github/workflows/documentation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3232

3333
- name: Setup node
34-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
34+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
3535
with:
3636
node-version: 22
3737

@@ -52,7 +52,7 @@ jobs:
5252
- run: git fetch --depth=1 --tags # download all tags for documentation
5353

5454
- name: Setup node
55-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
55+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
5656
with:
5757
node-version: 22
5858

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Encryption Tests
2+
3+
on:
4+
push:
5+
branches: ['master']
6+
pull_request:
7+
branches: [ 'master' ]
8+
workflow_dispatch: {}
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
id-token: write
14+
15+
jobs:
16+
run-tests:
17+
permissions:
18+
# required for all workflows
19+
security-events: write
20+
id-token: write
21+
contents: write
22+
runs-on: ubuntu-latest
23+
name: Encryption tests
24+
env:
25+
FORCE_COLOR: true
26+
steps:
27+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
28+
- name: Setup node
29+
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
30+
with:
31+
node-version: 22
32+
- name: Install Dependencies
33+
run: npm install
34+
- name: Install mongodb-client-encryption
35+
run: npm install mongodb-client-encryption
36+
- name: Setup Tests
37+
run: npm run setup-test-encryption
38+
- name: Run Tests
39+
run: npm run test-encryption

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2626

2727
- name: Setup node
28-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
28+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2929
with:
3030
node-version: 22
3131

@@ -61,7 +61,7 @@ jobs:
6161
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6262

6363
- name: Setup node
64-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
64+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
6565
with:
6666
node-version: ${{ matrix.node }}
6767

@@ -96,7 +96,7 @@ jobs:
9696
steps:
9797
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
9898
- name: Setup node
99-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
99+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
100100
with:
101101
node-version: 22
102102
- name: Load MongoDB binary cache
@@ -108,7 +108,7 @@ jobs:
108108
- name: Setup Deno
109109
uses: denoland/setup-deno@v2
110110
with:
111-
deno-version: v1.37.x
111+
deno-version: v2.1.x
112112
- run: deno --version
113113
- run: npm install
114114
- name: Run Deno tests
@@ -124,7 +124,7 @@ jobs:
124124
steps:
125125
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
126126
- name: Setup node
127-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
127+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
128128
with:
129129
node-version: 22
130130
- run: npm install

.github/workflows/tidelift-alignment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1919
- name: Setup node
20-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
20+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2121
with:
2222
node-version: 22
2323
- name: Alignment

.github/workflows/tsd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2424

2525
- name: Setup node
26-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
26+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
2727
with:
2828
node-version: 22
2929

@@ -41,7 +41,7 @@ jobs:
4141
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4242

4343
- name: Setup node
44-
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
44+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
4545
with:
4646
node-version: 22
4747

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ examples/ecommerce-netlify-functions/.netlify/state.json
6767

6868
notes.md
6969
list.out
70+
71+
data
72+
*.pid

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ If you have a question about Mongoose (not a bug report) please post it to eithe
4646
* execute `npm run test-tsd` to run the typescript tests
4747
* execute `npm run ts-benchmark` to run the typescript benchmark "performance test" for a single time.
4848
* execute `npm run ts-benchmark-watch` to run the typescript benchmark "performance test" while watching changes on types folder. Note: Make sure to commit all changes before executing this command.
49+
* in order to run tests that require an cluster with encryption locally, run `npm run setup-test-encryption` followed by `npm run test-encryption`. Alternatively, you can start an encrypted cluster using the `scripts/configure-cluster-with-encryption.sh` file.
50+
* These scripts can take a few minutes to run.
51+
* To change an encryption configuration, it is recommended to follow these steps:
52+
* Edit the variables in `scripts/configure-cluster-with-encryption.sh` with your desired configuration.
53+
* Restart your shell.
54+
* Delete the `data/` directory if it exists.
55+
* Finally, run the configuration script.
4956

5057
## Documentation
5158

lib/aggregate.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const getConstructorName = require('./helpers/getConstructorName');
1313
const prepareDiscriminatorPipeline = require('./helpers/aggregate/prepareDiscriminatorPipeline');
1414
const stringifyFunctionOperators = require('./helpers/aggregate/stringifyFunctionOperators');
1515
const utils = require('./utils');
16+
const { modelSymbol } = require('./helpers/symbols');
1617
const read = Query.prototype.read;
1718
const readConcern = Query.prototype.readConcern;
1819

@@ -46,13 +47,17 @@ const validRedactStringValues = new Set(['$$DESCEND', '$$PRUNE', '$$KEEP']);
4647
* @see MongoDB https://www.mongodb.com/docs/manual/applications/aggregation/
4748
* @see driver https://mongodb.github.io/node-mongodb-native/4.9/classes/Collection.html#aggregate
4849
* @param {Array} [pipeline] aggregation pipeline as an array of objects
49-
* @param {Model} [model] the model to use with this aggregate.
50+
* @param {Model|Connection} [modelOrConn] the model or connection to use with this aggregate.
5051
* @api public
5152
*/
5253

53-
function Aggregate(pipeline, model) {
54+
function Aggregate(pipeline, modelOrConn) {
5455
this._pipeline = [];
55-
this._model = model;
56+
if (modelOrConn == null || modelOrConn[modelSymbol]) {
57+
this._model = modelOrConn;
58+
} else {
59+
this._connection = modelOrConn;
60+
}
5661
this.options = {};
5762

5863
if (arguments.length === 1 && Array.isArray(pipeline)) {
@@ -1041,12 +1046,24 @@ Aggregate.prototype.pipeline = function() {
10411046
*/
10421047

10431048
Aggregate.prototype.exec = async function exec() {
1044-
if (!this._model) {
1049+
if (!this._model && !this._connection) {
10451050
throw new Error('Aggregate not bound to any Model');
10461051
}
10471052
if (typeof arguments[0] === 'function') {
10481053
throw new MongooseError('Aggregate.prototype.exec() no longer accepts a callback');
10491054
}
1055+
1056+
if (this._connection) {
1057+
if (!this._pipeline.length) {
1058+
throw new MongooseError('Aggregate has empty pipeline');
1059+
}
1060+
1061+
this._optionsForExec();
1062+
1063+
const cursor = await this._connection.client.db().aggregate(this._pipeline, this.options);
1064+
return await cursor.toArray();
1065+
}
1066+
10501067
const model = this._model;
10511068
const collection = this._model.collection;
10521069

0 commit comments

Comments
 (0)