Filter including field in formula

后端 未结 1 1992
执念已碎
执念已碎 2021-01-15 06:52

I want to filter a collection including collection\'s fields in the criteria.

- myCollection
|- name (string)
|- field1 (int)
|- field2 (int)
相关标签:
1条回答
  • 2021-01-15 07:32

    There is no way to specify field references in the value of an expression.

    The best approach I can think of is to store the value of field2 - field1 in a separate field, so that you can compare that against a constant. E.g. if you store the delta of field2 and field 1 in delta_field2_field2, you'd get this query:

    db.collection('myCollection').where('delta_field2_field2','<', 0)
    

    Then if you store the sum of field 1 and 2 in sum_field1_field2 you'd get:

    db.collection('myCollection').where('sum_field1_field2','<',1000)
    

    You'll see this is a common theme across NoSQL databases: if an operator you want isn't built-in, you can often add data to your model to allow for the use-case.

    0 讨论(0)
提交回复
热议问题