Google datastore multiple values for the same property

1.2k views Asked by At

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

There are 1 answers

3
Andrei Volgin On BEST ANSWER

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