Skip to content

Commit

Permalink
fix: query aggregation pipeline cannot handle value of type Date wh…
Browse files Browse the repository at this point in the history
…en `directAccess: true` (parse-community#8167)
  • Loading branch information
dblythy authored Sep 17, 2022
1 parent cec3071 commit e424137
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit e424137

Please sign in to comment.