Skip to content

Commit e424137

Browse files
authored
fix: query aggregation pipeline cannot handle value of type Date when directAccess: true (parse-community#8167)
1 parent cec3071 commit e424137

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

spec/ParseQuery.Aggregate.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,23 @@ describe('Parse.Query Aggregate testing', () => {
666666
});
667667
});
668668

669+
it('should aggregate with Date object (directAccess)', async () => {
670+
const rest = require('../lib/rest');
671+
const auth = require('../lib/Auth');
672+
const TestObject = Parse.Object.extend('TestObject');
673+
const date = new Date();
674+
await new TestObject({ date: date }).save(null, { useMasterKey: true });
675+
const config = Config.get(Parse.applicationId);
676+
const resp = await rest.find(
677+
config,
678+
auth.master(config),
679+
'TestObject',
680+
{},
681+
{ pipeline: [{ $match: { date: { $lte: new Date() } } }] }
682+
);
683+
expect(resp.results.length).toBe(1);
684+
});
685+
669686
it('match comparison query', done => {
670687
const options = Object.assign({}, masterKeyOptions, {
671688
body: {

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

+3
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,9 @@ export class MongoStorageAdapter implements StorageAdapter {
952952
// an operator in it (like $gt, $lt, etc). Because of this I felt it was easier to make this a
953953
// recursive method to traverse down to the "leaf node" which is going to be the string.
954954
_convertToDate(value: any): any {
955+
if (value instanceof Date) {
956+
return value;
957+
}
955958
if (typeof value === 'string') {
956959
return new Date(value);
957960
}

0 commit comments

Comments
 (0)