首页 > 解决方案 > 如何使用objectify在谷歌数据存储上应用不同的?

问题描述

我正在尝试获取一些在属性上具有不同值的实体。比如说,我有一个名为消息的实体。它有一些属性,比如 personId、typeId、convId、createdTime 等。我想要获取具有不同 convIds 的 personId p1 的消息。我怎样才能做到这一点。

我已经提到 Executing DISTINCT query with objectify for app engine and some others。并尝试了这样的事情。

ofy().load().type(messages.class).limit( 10 ).filter("personId ==", "p1").order("-createdTime").project("convId").distinct(true).list();

我确信有一些实体具有这种组合。但它没有获取任何实体。请帮我解决一下这个。

标签: google-app-enginegoogle-cloud-datastoredistinctobjectify

解决方案


不幸的是,您的查询无效。对于投影查询,您需要distinct使用您排序的值(即 -createdTime)。要使用 distinct,您需要按 convId 排序。

https://cloud.google.com/datastore/docs/concepts/queries#restrictions_on_queries有更多详细信息。


推荐阅读