同一属性的谷歌数据存储多个值 [英] Google datastore multiple values for the same property

查看:279
本文介绍了同一属性的谷歌数据存储多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌数据存储为一个Android应用程序,后端是用Java编写。在一个表中,我想设置多个值相同的属性:

I am using Google Datastore for an Android application, the backend is written in Java. In one table, I want to set multiple values to the same property:

Entity newGroup = new Entity("group");
newGroup.setProperty("member", "A");
newGroup.setProperty("member", "B");
newGroup.setProperty("member", "C");
datastore.put(newGroup);

然后我要查询找到用户所属的所有组,我做到以下几点:

I then want to query to find all groups a user belongs to, I do the following:

    Query.Filter filter = new Query.FilterPredicate("member", Query.FilterOperator.EQUAL, "A");
    Query q = new Query("group").setFilter(filter);

    PreparedQuery pq = datastore.prepare(q);

但是,查询不产生任何结果。在本文档中提到,如果属性中的至少一个值的过滤器匹配,则实体被返回,这混淆了我

However, the query does not generate any result. In the documentation it is mentioned that if at least one value of the property matches the filter, the entity is returned, which confuses me.

感谢您!

推荐答案

它应该是:

List<String> members = new ArrayList<String>(3);
members.add("A");
members.add("B");
members.add("C");

Entity newGroup = new Entity("group");
newGroup.setProperty("member", members);
datastore.put(newGroup);

这篇关于同一属性的谷歌数据存储多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆