feat(AggregateRouter): support native mongodb syntax in aggregation pipelines (#7339)
This commit is contained in:
committed by
GitHub
parent
381e9bf014
commit
8fddac39bf
@@ -3,6 +3,7 @@ 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) {
|
||||
@@ -91,22 +92,30 @@ export class AggregateRouter extends ClassesRouter {
|
||||
|
||||
static transformStage(stageName, stage) {
|
||||
if (stageName === 'group') {
|
||||
if (Object.prototype.hasOwnProperty.call(stage[stageName], '_id')) {
|
||||
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;
|
||||
}
|
||||
if (!Object.prototype.hasOwnProperty.call(stage[stageName], '_id')) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
`Invalid parameter for query: group. Please use objectId instead of _id`
|
||||
`Invalid parameter for query: group. Missing key _id`
|
||||
);
|
||||
}
|
||||
if (!Object.prototype.hasOwnProperty.call(stage[stageName], 'objectId')) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
`Invalid parameter for query: group. objectId is required`
|
||||
);
|
||||
}
|
||||
stage[stageName]._id = stage[stageName].objectId;
|
||||
delete stage[stageName].objectId;
|
||||
}
|
||||
return { [`$${stageName}`]: stage[stageName] };
|
||||
|
||||
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] };
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
|
||||
Reference in New Issue
Block a user