gcloud数据存储区:我可以使用IN或Contains运算符进行过滤吗? [英] gcloud datastore: Can I filter with IN or Contains operator?

查看:53
本文介绍了gcloud数据存储区:我可以使用IN或Contains运算符进行过滤吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是数据存储区gCloud的新宠.我想过滤一个名为得分"的实体,将所有与公司列表相关的得分打分.我的实体的组成如下:

I am a new bee with the Datastore gCloud. And I want to filter in an entity called Score all the scores that have relation with a list of companies. My entity is formed as follows:

{
    "company_id": 1,
    "score": 100, 
}

我有几个具有不同公司ID的实体.我尝试使用query.add_filter命令进行过滤,但收到错误ValueError:

I have several entities with different company IDs. I tried to filter using the query.add_filter command but got the error ValueError:

(无效的表达式:"IN"",请使用以下其中一项:=,<,< =,>,> =.")

('Invalid expression: "IN"', 'Please use one of: =, <, <=,>,> =.')

对于我来说,错误的原因非常清楚,但是除了上述错误消息中列出的类型之外,除了如何使用IN或CONTAINS运行过滤器外,我在文档中没有找到任何内容.

The reason for the error is very clear to me, but I have not found anything in the documentation on how to run filters with IN or CONTAINS, in addition to types other than those listed in the above error message.

推荐答案

数据存储区不支持您要查找的过滤器运算符. 过滤器:

The filters operators you seek are not supported by the datastore. The only supported ones are listed in Filters:

比较运算符可以是以下任意一种:

The comparison operator can be any of the following:

Operator                  Meaning
EQUAL                     Equal to
LESS_THAN                 Less than
LESS_THAN_OR_EQUAL        Less than or equal to
GREATER_THAN              Greater than
GREATER_THAN_OR_EQUAL     Greater than or equal to

某些客户端库可能会提供一些等效项,但有一定的局限性.例如,标准环境GAE特定的ndb库(在您的上下文中不可用)提供了这种支持. !=和IN操作中的示例可以很有用,因为您可以在代码中以类似的方式实现它:

Some of the client libraries may offer some equivalents, but with limitations. For example the standard environment GAE-specific ndb library (not usable in your context) offers such support. The example from The != and IN Operations can be useful as you can implement it in a similar manner in your code:

类似地,IN操作

Similarly, the IN operation

property IN [value1, value2, ...]

测试可能值列表中的成员资格,是 实施为

which tests for membership in a list of possible values, is implemented as

(property == value1) OR (property == value2) OR ...

这篇关于gcloud数据存储区:我可以使用IN或Contains运算符进行过滤吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆