Skip to content

Commit 303f7ae

Browse files
davimacedodplewis
authored andcommitted
Fix: aggregate not matching null values (parse-community#6043)
* Fix: aggregate not matching null values * Exclude Postgres from this new test - it does not even support and is not working correctly - should be addressed separately
1 parent 270a552 commit 303f7ae

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

spec/ParseQuery.Aggregate.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,52 @@ describe('Parse.Query Aggregate testing', () => {
941941
});
942942
});
943943

944+
it_exclude_dbs(['postgres'])('match null values', async () => {
945+
const obj1 = new Parse.Object('MyCollection');
946+
obj1.set('language', 'en');
947+
obj1.set('otherField', 1);
948+
const obj2 = new Parse.Object('MyCollection');
949+
obj2.set('language', 'en');
950+
obj2.set('otherField', 2);
951+
const obj3 = new Parse.Object('MyCollection');
952+
obj3.set('language', null);
953+
obj3.set('otherField', 3);
954+
const obj4 = new Parse.Object('MyCollection');
955+
obj4.set('language', null);
956+
obj4.set('otherField', 4);
957+
const obj5 = new Parse.Object('MyCollection');
958+
obj5.set('language', 'pt');
959+
obj5.set('otherField', 5);
960+
const obj6 = new Parse.Object('MyCollection');
961+
obj6.set('language', 'pt');
962+
obj6.set('otherField', 6);
963+
await Parse.Object.saveAll([obj1, obj2, obj3, obj4, obj5, obj6]);
964+
965+
expect(
966+
(await new Parse.Query('MyCollection').aggregate([
967+
{
968+
match: {
969+
language: { $in: [null, 'en'] },
970+
},
971+
},
972+
]))
973+
.map(value => value.otherField)
974+
.sort()
975+
).toEqual([1, 2, 3, 4]);
976+
977+
expect(
978+
(await new Parse.Query('MyCollection').aggregate([
979+
{
980+
match: {
981+
$or: [{ language: 'en' }, { language: null }],
982+
},
983+
},
984+
]))
985+
.map(value => value.otherField)
986+
.sort()
987+
).toEqual([1, 2, 3, 4]);
988+
});
989+
944990
it('project query', done => {
945991
const options = Object.assign({}, masterKeyOptions, {
946992
body: {

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,9 @@ export class MongoStorageAdapter implements StorageAdapter {
841841
// As much as I hate recursion...this seemed like a good fit for it. We're essentially traversing
842842
// down a tree to find a "leaf node" and checking to see if it needs to be converted.
843843
_parseAggregateArgs(schema: any, pipeline: any): any {
844-
if (Array.isArray(pipeline)) {
844+
if (pipeline === null) {
845+
return null;
846+
} else if (Array.isArray(pipeline)) {
845847
return pipeline.map(value => this._parseAggregateArgs(schema, value));
846848
} else if (typeof pipeline === 'object') {
847849
const returnValue = {};

0 commit comments

Comments
 (0)