简体   繁体   English

与IN相反的对象化查询

[英]Objectify Query Opposite of IN

Suppose I have an entity kind called EntityA and I have a list of EntityA ids. 假设我有一个称为EntityA的实体类型,并且有一个EntityA id的列表。 How can I query all EntityA entities from my database which the id IS NOT in the list of EntityA ids that I have? 如何从我的数据库中查询ID不在我拥有的EntityA ID列表中的所有EntityA实体?

I'm trying to do something like: 我正在尝试做类似的事情:

ofy().load().type(EntityA.class).filter("!IN", entityAKeys);

How could I get it working? 我该如何运作? Is it possible? 可能吗?

No, this is not supported as Cloud Datastore only allows queries supported by an index to ensure they don't break as they your dataset scales. 否,不支持此操作,因为Cloud Datastore仅允许索引支持的查询以确保它们不会随数据集扩展而中断。

You will have to query for all entities in kind EntityA and filter out those in entityAKeys on the client side yourself. 您将必须查询EntityA类的所有实体,并自己过滤掉客户端上的entityAKeys中的实体。

So I ended up doing like: 所以我最终做了这样的事情:

List<Key<MXChallenge>> keyList = new ArrayList<>();
List<Key<MXChallenge>> searchInKeys = ofy().load().type(MXChallenge.class).keys().list();

for(Long id : alreadyRetrieved){
    keyList.add(Key.create(MXChallenge.class, id));
}

searchInKeys.removeAll(keyList);

QueryResultIterator<MXChallenge> iteratorChallenges = ofy().load()
        .type(MXChallenge.class).filter("colour", "blue").filterKey("IN", searchInKeys).iterator();

I'm nor sure in terms of performance though but as it is a "keys-only" operation I'd say it should be fine. 我不确定性能,但是由于它是“仅键”操作,因此我认为应该没问题。

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

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