Skip to content

Commit 5561d82

Browse files
RaschidJFRdplewis
andauthored
feat(ParseQuery): support using aggregate on top of constructed query (#1170)
Co-authored-by: Diamond Lewis <[email protected]>
1 parent 3f30a38 commit 5561d82

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

integration/test/ParseQueryAggregateTest.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ describe('Parse Aggregate Query', () => {
9696
expect(results[0].tempPointer.value).toEqual(2);
9797
});
9898

99+
it('aggregate pipeline on top of a simple query', async done => {
100+
const pipeline = {
101+
group: { objectId: '$name' },
102+
};
103+
let results = await new Parse.Query(TestObject)
104+
.equalTo('name', 'foo')
105+
.aggregate(pipeline);
106+
107+
expect(results.length).toBe(1);
108+
109+
results = await new Parse.Query(TestObject)
110+
.equalTo('score', 20)
111+
.aggregate(pipeline);
112+
113+
expect(results.length).toBe(1);
114+
115+
done();
116+
});
117+
99118
it('distinct query', () => {
100119
const query = new Parse.Query(TestObject);
101120
return query.distinct('score').then((results) => {

src/ParseQuery.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,11 @@ class ParseQuery {
781781
throw new Error('Invalid pipeline must be Array or Object');
782782
}
783783

784+
if (Object.keys(this._where || {}).length) {
785+
if(!Array.isArray(pipeline)) pipeline = [pipeline];
786+
pipeline.unshift({ match: this._where });
787+
}
788+
784789
const params = {
785790
pipeline,
786791
hint: this._hint,

0 commit comments

Comments
 (0)