Skip to content
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: query aggregation pipeline cannot handle value of type Date when directAccess: true #8167

Merged
merged 5 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions spec/ParseQuery.Aggregate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,23 @@ describe('Parse.Query Aggregate testing', () => {
});
});

it('should aggregate with Date object (directAccess)', async () => {
const rest = require('../lib/rest');
const auth = require('../lib/Auth');
const TestObject = Parse.Object.extend('TestObject');
const date = new Date();
await new TestObject({ date: date }).save(null, { useMasterKey: true });
const config = Config.get(Parse.applicationId);
const resp = await rest.find(
config,
auth.master(config),
'TestObject',
{},
{ pipeline: [{ $match: { date: { $lte: new Date() } } }] }
);
expect(resp.results.length).toBe(1);
});

it('match comparison query', done => {
const options = Object.assign({}, masterKeyOptions, {
body: {
Expand Down
3 changes: 3 additions & 0 deletions src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,9 @@ export class MongoStorageAdapter implements StorageAdapter {
// an operator in it (like $gt, $lt, etc). Because of this I felt it was easier to make this a
// recursive method to traverse down to the "leaf node" which is going to be the string.
_convertToDate(value: any): any {
if (value instanceof Date) {
return value;
}
if (typeof value === 'string') {
return new Date(value);
}
Expand Down