简体   繁体   English

具有多个过滤器的数据存储区查询

[英]Datastore Query with multiple filters

There is requirement to query on multiple properties with '!=' on one property and '<=' on another property. 需要查询多个属性,其中一个属性为“!=”,另一属性为“ <=”。

But seeing the Datastore docs , it is not possible. 但是看不到数据存储文档,这是不可能的。 How can we make it possible as i dont want to create multiple indexes. 我们如何才能实现这一目标,因为我不想创建多个索引。

You simply cannot. 你根本不能。 You'll have a couple of choices here to work around that: 您可以在此处选择几种方法来解决:

1- filter on one inequality, then in your code, filter for <=. 1-过滤一个不等式,然后在您的代码中过滤<=。 You will get a bit too many results, but it will work. 您会得到太多的结果,但是它将起作用。

2- Create a boolean property referring to your second condition. 2-创建一个引用第二个条件的布尔属性。 Add a boolean "smaller_than_x". 添加一个布尔值“ smaller_than_x”。 Whenever you create the entity, the field you need filtered on <=, check if it is smaller than x. 每当创建实体时,需要在<=上过滤的字段,请检查其是否小于x。 If it is, make the boolean true. 如果是,请将布尔值设为true。 Then you can filter on the boolean with an equality (this assumes that you always have the same value for x. if your value is dynamic, method 1 will be your best bet) 然后,您可以使用等式过滤布尔值(这假设x始终具有相同的值。如果您的值是动态的,则方法1是最佳选择)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM