简体   繁体   English

Google Cloud Datastore是否获得将布尔值设置为false或null的实体?

[英]Google Cloud Datastore get entities that have a boolean set to false or null?

I have a bunch of entities with a boolean field that can either be: true, false, or null (the actual null value). 我有一堆带有布尔值字段的实体,它们可以是:true,false或null (实际的null值)。 I need to retrieve all the entities that have this field set to null or false. 我需要检索所有将此字段设置为null或false的实体。 I know that that GCD doesn't support a not equal query but I think I got it to work by querying for all the entities that have the field less than true. 我知道GCD不支持不相等的查询,但我想我可以通过查询字段小于true的所有实体来使其工作。 It seems to work but I am not sure why it works. 它似乎有效,但我不确定为什么有效。 Are null and false always less than true? null和false总是小于true吗?

Any of these work: 以下任何一项工作:

test_query = Test.query(Test.bool != True).fetch()
test_query = Test.query(Test.bool.IN([False, None])).fetch()
test_query = Test.query(Test.bool < True).fetch()

In Python: 在Python中:

>>> None < False < True
True

Datastore not supports OR and != (not equal) operators natively. 数据存储本身不支持OR和!=(不相等)运算符。

Python implementations, of != is fully programmatic and have number of limitation when used with another query operations. !=的Python实现是完全编程的,与其他查询操作一起使用时有一定数量的限制。

Search with IN operator when [False, None] provided will cause multiple query to be launched and merged in a single result with this call. 如果提供[False,None],则使用IN运算符进行搜索将导致启动多个查询,并通过此调用将其合并到单个结果中。

The '< True' operation will not find properties without any value (empty val) as it is not indexed, but will find false and null values and this can be done in a single query. '<True'操作将找不到没有任何值的属性(空值),因为它没有被索引,但是将找到false和null值,这可以在单个查询中完成。

So, the best option will be (on JavaScript): 因此,最好的选择是(在JavaScript上):

let query = db.createQuery("SomeNamespace", "SomeKind")
    .filter("property", "<", true);

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

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