gcloud datastore: Can I filter with IN or Contains operator?

我怕爱的太早我们不能终老 提交于 2019-12-11 17:46:10

问题


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, 
}

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

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

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.


回答1:


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

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:

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 ...


来源:https://stackoverflow.com/questions/49582670/gcloud-datastore-can-i-filter-with-in-or-contains-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!