parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.91k stars 4.78k forks source link

aggregate pipeline projected date field can not be recognized properly #6343

Open victorx98 opened 4 years ago

victorx98 commented 4 years ago

Sourcefile: https://github.com/parse-community/parse-server/blob/master/src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Function name: _parseAggregateArgs()

The purpose of the function is to

recursively traverse the pipeline and convert any Pointer or Date columns

But it can only recognize existing fields defined in the collection schema. If we create a new Data field in project stage, it can not recognize it and the query won't work.

Examples: any match on startTime will work, but not on endTime, which is generated in project stage.

var pipeline = [     {match: {_p_user: "_User$"+userId},},     {       project: {                 _p_user: 1,                 startTime: 1,                 "endTime": {$add: ["$startTime", {$multiply: ["$duration",60000]}]}                 }     }, // startTime can be recognized as Date() type, thus the query will work     {match: {"startTime": {$gt: new Date()}}}, // endTime can not be recognized as Date type, any query on endTime will fail     // {match: {"endTime": {$gt: new Date()}}},     {limit: 10},   ];

victorx98 commented 4 years ago

I think issue #6333 is talking about the same problem. Maybe we can merge these two issues.