Google datastore multiple values for the same property

本小妞迷上赌 提交于 2019-12-25 06:06:10

问题


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.

Thank you!


回答1:


It should be:

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);


来源:https://stackoverflow.com/questions/30733825/google-datastore-multiple-values-for-the-same-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!