Skip to content

Commit a78aec6

Browse files
committed
Merge branch 'pr-migrations'
# Conflicts: # spec/DefinedSchemas.spec.js # src/SchemaMigrations/DefinedSchemas.js # src/SchemaMigrations/Migrations.js
2 parents 4c1d2f6 + d244d56 commit a78aec6

File tree

10 files changed

+257
-50
lines changed

10 files changed

+257
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ ___
105105
- Add official support for MongoDB 5.0 (Manuel Trezza) [#7469](https://github.com/parse-community/parse-server/pull/7469)
106106

107107
### Other Changes
108+
- Support native mongodb syntax in aggregation pipelines (Raschid JF Rafeally) [#7339](https://github.com/parse-community/parse-server/pull/7339)
108109
- Fix error when a not yet inserted job is updated (Antonio Davi Macedo Coelho de Castro) [#7196](https://github.com/parse-community/parse-server/pull/7196)
109110
- request.context for afterFind triggers (dblythy) [#7078](https://github.com/parse-community/parse-server/pull/7078)
110111
- Winston Logger interpolating stdout to console (dplewis) [#7114](https://github.com/parse-community/parse-server/pull/7114)

DEPRECATIONS.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
The following is a list of deprecations, according to the [Deprecation Policy](https://github.com/parse-community/parse-server/blob/master/CONTRIBUTING.md#deprecation-policy). After a feature becomes deprecated, and giving developers time to adapt to the change, the deprecated feature will eventually be removed, leading to a breaking change. Developer feedback during the deprecation period may postpone the introduction of the breaking change.
44

5-
| Feature | Issue | Deprecation [ℹ️][i_deprecation] | Planned Removal [ℹ️][i_removal] | Status [ℹ️][i_status] | Notes |
6-
|---------|----|------------------|----------------------|----------|-------|
7-
(none)
8-
5+
| Feature | Issue | Deprecation [ℹ️][i_deprecation] | Planned Removal [ℹ️][i_removal] | Status [ℹ️][i_status] | Notes |
6+
|-----------------------------------------------|----------------------------------------------------------------------|---------------------------------|---------------------------------|-----------------------|-------|
7+
| Native MongoDB syntax in aggregation pipeline | [#7338](https://github.com/parse-community/parse-server/issues/7338) | 5.0.0 (2022) | 6.0.0 (2023) | deprecated | - |
98

109
[i_deprecation]: ## "The version and date of the deprecation."
1110
[i_removal]: ## "The version and date of the planned removal."
12-
[i_status]: ## "The current status of the deprecation: deprecated (the feature is deprecated and still available), removed (the deprecated feature has been removed and is unavailable), retracted (the deprecation has been retracted and the feature will not be removed."
11+
[i_status]: ## "The current status of the deprecation: deprecated (the feature is deprecated and still available), removed (the deprecated feature has been removed and is unavailable), retracted (the deprecation has been retracted and the feature will not be removed."

spec/AggregateRouter.spec.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const AggregateRouter = require('../lib/Routers/AggregateRouter').AggregateRouter;
22

33
describe('AggregateRouter', () => {
4+
// TODO: update pipeline syntax. See [#7339](https://bit.ly/3incnWx)
45
it('get pipeline from Array', () => {
56
const body = [
67
{
@@ -12,6 +13,7 @@ describe('AggregateRouter', () => {
1213
expect(result).toEqual(expected);
1314
});
1415

16+
// TODO: update pipeline syntax. See [#7339](https://bit.ly/3incnWx)
1517
it('get pipeline from Object', () => {
1618
const body = {
1719
group: { objectId: {} },
@@ -21,6 +23,7 @@ describe('AggregateRouter', () => {
2123
expect(result).toEqual(expected);
2224
});
2325

26+
// TODO: update pipeline syntax. See [#7339](https://bit.ly/3incnWx)
2427
it('get pipeline from Pipeline Operator (Array)', () => {
2528
const body = {
2629
pipeline: [
@@ -34,6 +37,7 @@ describe('AggregateRouter', () => {
3437
expect(result).toEqual(expected);
3538
});
3639

40+
// TODO: update pipeline syntax. See [#7339](https://bit.ly/3incnWx)
3741
it('get pipeline from Pipeline Operator (Object)', () => {
3842
const body = {
3943
pipeline: {
@@ -45,6 +49,7 @@ describe('AggregateRouter', () => {
4549
expect(result).toEqual(expected);
4650
});
4751

52+
// TODO: update pipeline syntax. See [#7339](https://bit.ly/3incnWx)
4853
it('get pipeline fails multiple keys in Array stage ', () => {
4954
const body = [
5055
{
@@ -59,6 +64,7 @@ describe('AggregateRouter', () => {
5964
}
6065
});
6166

67+
// TODO: update pipeline syntax. See [#7339](https://bit.ly/3incnWx)
6268
it('get pipeline fails multiple keys in Pipeline Operator Array stage ', () => {
6369
const body = {
6470
pipeline: [
@@ -75,6 +81,7 @@ describe('AggregateRouter', () => {
7581
}
7682
});
7783

84+
// TODO: update pipeline syntax. See [#7339](https://bit.ly/3incnWx)
7885
it('get search pipeline from Pipeline Operator (Array)', () => {
7986
const body = {
8087
pipeline: {
@@ -85,4 +92,73 @@ describe('AggregateRouter', () => {
8592
const result = AggregateRouter.getPipeline(body);
8693
expect(result).toEqual(expected);
8794
});
95+
96+
it('support stage name starting with `$`', () => {
97+
const body = {
98+
$match: { someKey: 'whatever' },
99+
};
100+
const expected = [{ $match: { someKey: 'whatever' } }];
101+
const result = AggregateRouter.getPipeline(body);
102+
expect(result).toEqual(expected);
103+
});
104+
105+
it('support nested stage names starting with `$`', () => {
106+
const body = [
107+
{
108+
lookup: {
109+
from: 'ACollection',
110+
let: { id: '_id' },
111+
as: 'results',
112+
pipeline: [
113+
{
114+
$match: {
115+
$expr: {
116+
$eq: ['$_id', '$$id'],
117+
},
118+
},
119+
},
120+
],
121+
},
122+
},
123+
];
124+
const expected = [
125+
{
126+
$lookup: {
127+
from: 'ACollection',
128+
let: { id: '_id' },
129+
as: 'results',
130+
pipeline: [
131+
{
132+
$match: {
133+
$expr: {
134+
$eq: ['$_id', '$$id'],
135+
},
136+
},
137+
},
138+
],
139+
},
140+
},
141+
];
142+
const result = AggregateRouter.getPipeline(body);
143+
expect(result).toEqual(expected);
144+
});
145+
146+
it('support the use of `_id` in stages', () => {
147+
const body = [
148+
{ match: { _id: 'randomId' } },
149+
{ sort: { _id: -1 } },
150+
{ addFields: { _id: 1 } },
151+
{ group: { _id: {} } },
152+
{ project: { _id: 0 } },
153+
];
154+
const expected = [
155+
{ $match: { _id: 'randomId' } },
156+
{ $sort: { _id: -1 } },
157+
{ $addFields: { _id: 1 } },
158+
{ $group: { _id: {} } },
159+
{ $project: { _id: 0 } },
160+
];
161+
const result = AggregateRouter.getPipeline(body);
162+
expect(result).toEqual(expected);
163+
});
88164
});

spec/DefinedSchemas.spec.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,12 @@ describe('DefinedSchemas', () => {
573573
schemas = await Parse.Schema.all();
574574
expect(schemas.length).toEqual(3);
575575
});
576-
it('should run beforeSchemaMigration before execution of DefinedSchemas', async () => {
576+
it('should run beforeMigration before execution of DefinedSchemas', async () => {
577577
let before = false;
578578
const server = await reconfigureServer({
579579
schema: {
580580
definitions: [{ className: '_User' }, { className: 'Test' }],
581-
beforeSchemaMigration: async () => {
581+
beforeMigration: async () => {
582582
expect(before).toEqual(false);
583583
before = true;
584584
},
@@ -588,6 +588,22 @@ describe('DefinedSchemas', () => {
588588
expect(before).toEqual(true);
589589
expect(server).toBeDefined();
590590
});
591+
it('should run afterMigration after execution of DefinedSchemas', async () => {
592+
let before = false;
593+
const server = await reconfigureServer({
594+
schema: {
595+
definitions: [{ className: '_User' }, { className: 'Test' }],
596+
afterMigration: async () => {
597+
expect(before).toEqual(false);
598+
before = true;
599+
},
600+
},
601+
});
602+
before = true;
603+
expect(before).toEqual(true);
604+
expect(server).toBeDefined();
605+
});
606+
591607
it('should use logger in case of error', async () => {
592608
const server = await reconfigureServer({ schema: { definitions: [{ className: '_User' }] } });
593609
const error = new Error('A test error');

0 commit comments

Comments
 (0)