0

My structure database (database product):

{
...
data: {
    value_a: 15.2,
    value_b: 7.1
  }
},
{
...
data: {
    value_a: 14.1
    value_b: 2.5
  }
},
{
...
data: {
    value_a: 16.7
    value_b: 5.2
  }
}

my request a) I would like to return a list of products if value_a is between 14 and 15 b) I would like to return a list product if value_a is between 14 and 15 and value_b is between 2 and 5.

I check the operator 'in' but isn't work for the (a).

 firestore().collection('products')
            .where("data.value_a", "in", [14, 15])
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

2 Answers2

1

The in operator only works if you have a list of values for value_a. To achieve what you want you should combine queries:

firestore().collection('product_geoloc')
    .where("data.value_a", ">=", 14)
    .where("data.value_a", "<=", 15)
Daniel Geffen
  • 1,777
  • 1
  • 11
  • 16
  • The second solution is definitely not possible. Please check this [answer](https://stackoverflow.com/questions/48340925/how-to-sort-firebase-records-by-two-fields-android). – Alex Mamo Aug 22 '21 at 13:23
1

a) I would like to return list of products if value_a is between 14 and 15

To solve this, you should use the following query:

firestore().collection('products')
        .where("data.value_a", ">=", 14)
        .where("data.value_a", ">=", 15)

However,

b) I would like to return a list product if value_a is between 14 and 15 and value_b is between 2 and 5.

It's not possible. There is no way you can filter records based on multiple properties. There is a workaround, so please check my answer from the following post:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193