You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Objectify中如何使用Firestore Datastore模式的!=、IN、NOT_IN过滤器

Objectify过滤器相关问题解答

问题1:关于!=和IN过滤器的注释是否过时?使用Objectify时这两个过滤器是否可正常工作?

是的,Objectify文档中“6+版本不支持!=或IN过滤器”的注释已经过时。随着Google Cloud Datastore全面迁移到Firestore in Datastore模式,底层SDK已支持!=和IN操作,Objectify后续版本(如7.x及以上)也完成了适配,现在这两个过滤器可以正常使用。

示例代码:

// 使用!=过滤器查询指定字段不等于某值的实体
ofy().load().type(YourEntity.class).filter("status !=", "DISABLED").list();

// 使用IN过滤器查询指定字段在集合内的实体
List<String> allowedIds = Arrays.asList("id1", "id2", "id3");
ofy().load().type(YourEntity.class).filter("entityId in", allowedIds).list();

问题2:如何编写NOT_IN过滤器?是否采用.filter("year not_in", yearList)这样的写法?

完全正确,Objectify支持通过not_in关键字实现NOT_IN过滤,写法就是.filter("year not_in", yearList)。

示例代码:

// 使用NOT_IN过滤器查询指定字段不在集合内的实体
List<Integer> excludeYears = Arrays.asList(2019, 2020, 2021);
ofy().load().type(YearRecord.class).filter("year not_in", excludeYears).list();

内容的提问来源于stack exchange,提问作者Micro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 17:22:39