feat: Remove deprecation DEPPS1: Native MongoDB syntax in aggregation pipeline (#8362)

BREAKING CHANGE: The MongoDB aggregation pipeline requires native MongoDB syntax instead of the custom Parse Server syntax; for example pipeline stage names require a leading dollar sign like `$match` and the MongoDB document ID is referenced using `_id` instead of `objectId` (#8362)
This commit is contained in:
Daniel
2023-01-06 01:53:43 +11:00
committed by GitHub
parent df00cbebe3
commit d0d30c4f13
8 changed files with 149 additions and 148 deletions

View File

@@ -2241,8 +2241,11 @@ export class PostgresStorageAdapter implements StorageAdapter {
});
stage.$match = collapse;
}
for (const field in stage.$match) {
for (let field in stage.$match) {
const value = stage.$match[field];
if (field === '_id') {
field = 'objectId';
}
const matchPatterns = [];
Object.keys(ParseToPosgresComparator).forEach(cmp => {
if (value[cmp]) {

View File

@@ -3,7 +3,6 @@ import rest from '../rest';
import * as middleware from '../middlewares';
import Parse from 'parse/node';
import UsersRouter from './UsersRouter';
import Deprecator from '../Deprecator/Deprecator';
export class AggregateRouter extends ClassesRouter {
handleFind(req) {
@@ -83,22 +82,30 @@ export class AggregateRouter extends ClassesRouter {
return pipeline.map(stage => {
const keys = Object.keys(stage);
if (keys.length != 1) {
throw new Error(`Pipeline stages should only have one key found ${keys.join(', ')}`);
if (keys.length !== 1) {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
`Pipeline stages should only have one key but found ${keys.join(', ')}.`
);
}
return AggregateRouter.transformStage(keys[0], stage);
});
}
static transformStage(stageName, stage) {
if (stageName === 'group') {
const skipKeys = ['distinct', 'where'];
if (skipKeys.includes(stageName)) {
return;
}
if (stageName[0] !== '$') {
throw new Parse.Error(Parse.Error.INVALID_QUERY, `Invalid aggregate stage '${stageName}'.`);
}
if (stageName === '$group') {
if (Object.prototype.hasOwnProperty.call(stage[stageName], 'objectId')) {
Deprecator.logRuntimeDeprecation({
usage: 'The use of objectId in aggregation stage $group',
solution: 'Use _id instead.',
});
stage[stageName]._id = stage[stageName].objectId;
delete stage[stageName].objectId;
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
`Cannot use 'objectId' in aggregation stage $group.`
);
}
if (!Object.prototype.hasOwnProperty.call(stage[stageName], '_id')) {
throw new Parse.Error(
@@ -107,15 +114,7 @@ export class AggregateRouter extends ClassesRouter {
);
}
}
if (stageName[0] !== '$') {
Deprecator.logRuntimeDeprecation({
usage: "Using aggregation stages without a leading '$'",
solution: `Try $${stageName} instead.`,
});
}
const key = stageName[0] === '$' ? stageName : `$${stageName}`;
return { [key]: stage[stageName] };
return { [stageName]: stage[stageName] };
}
mountRoutes() {