Skip to content
Permalink
Browse files
feat(firestore): support "!=" and "not-in" query operators (#3207)
Firestore Version 7.21.0 - September 17, 2020 - introduced support for
the "!=" (NOT_EQUAL) and "not-in" (NOT_IN) query operators:
https://firebase.google.com/support/release-notes/js#version_7210_-_september_17_2020

Query operator documentation:
https://firebase.google.com/docs/firestore/query-data/queries

This patch adds support for these two new operators and adds test
cases for them.
  • Loading branch information
jacksgt committed Nov 17, 2020
1 parent c731dd5 commit 5c440192105fe3e9b5dd1b584118b309113935e3
Showing with 22 additions and 1 deletion.
  1. +7 −0 firestore/integration_test.go
  2. +4 −0 firestore/query.go
  3. +11 −1 firestore/query_test.go
@@ -651,6 +651,13 @@ func TestIntegration_QueryDocuments(t *testing.T) {
}{
{q, wants},
{q.Where("q", ">", 1), wants[2:]},
{q.Where("q", "<", 1), wants[:1]},
{q.Where("q", "==", 1), wants[1:2]},
{q.Where("q", "!=", 0), wants[1:]},
{q.Where("q", ">=", 1), wants[1:]},
{q.Where("q", "<=", 1), wants[:2]},
{q.Where("q", "in", []int{0, 1}), wants[:2]},
{q.Where("q", "not-in", []int{0, 1}), wants[2:]},
{q.WherePath([]string{"q"}, ">", 1), wants[2:]},
{q.Offset(1).Limit(1), wants[1:2]},
{q.StartAt(1), wants[1:]},
@@ -500,8 +500,12 @@ func (f filter) toProto() (*pb.StructuredQuery_Filter, error) {
op = pb.StructuredQuery_FieldFilter_GREATER_THAN_OR_EQUAL
case "==":
op = pb.StructuredQuery_FieldFilter_EQUAL
case "!=":
op = pb.StructuredQuery_FieldFilter_NOT_EQUAL
case "in":
op = pb.StructuredQuery_FieldFilter_IN
case "not-in":
op = pb.StructuredQuery_FieldFilter_NOT_IN
case "array-contains":
op = pb.StructuredQuery_FieldFilter_ARRAY_CONTAINS
case "array-contains-any":
@@ -143,11 +143,21 @@ func TestQueryToProto(t *testing.T) {
in: q.Where("a", "==", float32(math.NaN())),
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, "==", math.NaN())},
},
{
desc: `q.Where("a", "!=", 3)`,
in: q.Where("a", "!=", 3),
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, "!=", 3)},
},
{
desc: `q.Where("a", "in", []int{7, 8})`,
in: q.Where("a", "in", []int{7, 8}),
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, "in", []int{7, 8})},
},
{
desc: `q.Where("a", "not-in", []int{9})`,
in: q.Where("a", "not-in", []int{9}),
want: &pb.StructuredQuery{Where: filtr([]string{"a"}, "not-in", []int{9})},
},
{
desc: `q.Where("c", "array-contains", 1)`,
in: q.Where("c", "array-contains", 1),
@@ -456,7 +466,7 @@ func TestQueryToProtoErrors(t *testing.T) {
q := coll.Query
for i, query := range []Query{
{}, // no collection ID
q.Where("x", "!=", 1), // invalid operator
q.Where("x", "<>", 1), // invalid operator
q.Where("~", ">", 1), // invalid path
q.WherePath([]string{"*", ""}, ">", 1), // invalid path
q.StartAt(1), // no OrderBy

0 comments on commit 5c44019

Please sign in to comment.