Skip to content

Commit

Permalink
fix(firestore): support not equals null query
Browse files Browse the repository at this point in the history
  • Loading branch information
pafry7 authored and mikehardy committed Jan 27, 2023
1 parent da82c10 commit b93699c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/firestore/e2e/Query/where.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ describe('firestore().collection().where()', function () {
firebase.firestore().collection(COLLECTION).where('foo.bar', '==', null);
});

it('allows null to be used with not equal operator', function () {
firebase.firestore().collection(COLLECTION).where('foo.bar', '!=', null);
});

it('throws if multiple inequalities on different paths is provided', function () {
try {
firebase.firestore().collection(COLLECTION).where('foo.bar', '>', 123).where('bar', '>', 123);
Expand Down
6 changes: 5 additions & 1 deletion packages/firestore/lib/FirestoreQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,11 @@ export default class FirestoreQuery {
);
}

if (isNull(value) && !this._modifiers.isEqualOperator(opStr)) {
if (
isNull(value) &&
!this._modifiers.isEqualOperator(opStr) &&
!this._modifiers.isNotEqualOperator(opStr)
) {
throw new Error(
"firebase.firestore().collection().where(_, _, *) 'value' is invalid. You can only perform equals comparisons on null",
);
Expand Down
4 changes: 4 additions & 0 deletions packages/firestore/lib/FirestoreQueryModifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export default class FirestoreQueryModifiers {
return OPERATORS[operator] === 'EQUAL';
}

isNotEqualOperator(operator) {
return OPERATORS[operator] === 'NOT_EQUAL';
}

isInOperator(operator) {
return (
OPERATORS[operator] === 'IN' ||
Expand Down

0 comments on commit b93699c

Please sign in to comment.