-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix: MongoDB aggregation pipeline with $dateSubtract
from $$NOW
returns no results
#9822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: MongoDB aggregation pipeline with $dateSubtract
from $$NOW
returns no results
#9822
Conversation
🚀 Thanks for opening this pull request! |
📝 WalkthroughWalkthroughA new aggregation test was added to verify the use of the Changes
Sequence Diagram(s)sequenceDiagram
participant TestSuite as Parse.Query Aggregate Test
participant DB as MongoDB Adapter
TestSuite->>DB: Create two TestObject instances with different dates
TestSuite->>DB: Execute aggregation pipeline with $dateSubtract from $$NOW
DB-->>TestSuite: Return objects matching date >= $$NOW - 2 days
TestSuite->>TestSuite: Assert only 1 result (date 1 day ago)
sequenceDiagram
participant Adapter as MongoStorageAdapter
participant Input as InputData
Input->>Adapter: Call _convertToDate(data)
Adapter->>Adapter: Check if string is a valid date
alt Valid date string
Adapter->>Input: Convert to Date object
else Invalid date string
Adapter->>Input: Return original string
end
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm warn EBADENGINE Unsupported engine { Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
spec/ParseQuery.Aggregate.spec.js (1)
442-470
: Excellent test for the$dateSubtract
fix!This test effectively verifies that MongoDB aggregation pipelines with
$dateSubtract
from$$NOW
return correct results. The test setup and assertions properly validate the fix.However, there's a comment error that should be corrected:
- const obj2 = new TestObject({ date: new Date(new Date().getTime() - 2 * 24 * 60 * 60 * 1_000) }); // 3 days ago + const obj2 = new TestObject({ date: new Date(new Date().getTime() - 2 * 24 * 60 * 60 * 1_000) }); // 2 days ago
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
spec/ParseQuery.Aggregate.spec.js
(1 hunks)src/Adapters/Storage/Mongo/MongoStorageAdapter.js
(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
spec/ParseQuery.Aggregate.spec.js (4)
Learnt from: RahulLanjewar93
PR: parse-community/parse-server#9744
File: spec/ParseLiveQuery.spec.js:0-0
Timestamp: 2025-04-30T19:31:35.344Z
Learning: In the Parse Server codebase, the functions in QueryTools.js are typically tested through end-to-end behavior tests rather than direct unit tests, even though the functions are exported from the module.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1312-1338
Timestamp: 2025-05-04T20:41:05.147Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`. The preferred pattern is to create a Promise that resolves when an expected event occurs, then await that Promise.
Learnt from: mtrezza
PR: parse-community/parse-server#9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: Tests in the parse-server repository should use promise-based approaches rather than callback patterns with `done()`. Use a pattern where a Promise is created that resolves when the event occurs, then await that promise.
🪛 Biome (1.9.4)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js
[error] 970-970: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.
TypeScript only syntax
(parse)
[error] 970-970: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.
TypeScript only syntax
(parse)
[error] 971-984: This code is unreachable
(lint/correctness/noUnreachable)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: PostgreSQL 15, PostGIS 3.3
- GitHub Check: PostgreSQL 15, PostGIS 3.4
- GitHub Check: PostgreSQL 16, PostGIS 3.5
- GitHub Check: PostgreSQL 17, PostGIS 3.5
- GitHub Check: Docker Build
- GitHub Check: PostgreSQL 15, PostGIS 3.5
- GitHub Check: Node 18
- GitHub Check: MongoDB 6, ReplicaSet
- GitHub Check: MongoDB 8, ReplicaSet
- GitHub Check: Redis Cache
- GitHub Check: MongoDB 7, ReplicaSet
- GitHub Check: Node 20
🔇 Additional comments (3)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js (3)
963-969
: Good documentation improvement!The JSDoc comment clearly explains the method's purpose and recursive behavior for handling aggregation pipeline objects.
975-975
: Excellent validation improvement!Using
Date.parse()
to validate date strings before conversion prevents invalid date strings from being converted toDate
objects, which addresses the core issue with$dateSubtract
operations.
977-984
: Good recursive object handling.The recursive processing of objects ensures that nested date values in aggregation pipelines are properly converted, which is essential for complex pipeline operations.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## alpha #9822 +/- ##
=======================================
Coverage 93.01% 93.01%
=======================================
Files 187 187
Lines 15094 15096 +2
Branches 174 174
=======================================
+ Hits 14039 14041 +2
Misses 1043 1043
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
## [8.2.3-alpha.1](8.2.2...8.2.3-alpha.1) (2025-07-13) ### Bug Fixes * MongoDB aggregation pipeline with `$dateSubtract` from `$$NOW` returns no results ([#9822](#9822)) ([847a274](847a274))
🎉 This change has been released in version 8.2.3-alpha.1 |
Pull Request
Issue
A MongoDB aggregation pipeline like this returns no results:
The reason is that Parse Server's aggregation pipeline parser only is able to handle simple date comparisons like:
But it doesn't handle more complex expressions where the comparison is not a Date string or Date object, but another logical expression.
Approach
Adapt aggregation pipeline parser to handle complex expressions.
Tasks