Radu Baciu Radu Baciu - 1 year ago 91
Android Question

Google datastore multiple values for the same property

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

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!

Answer Source

It should be:

List<String> members = new ArrayList<String>(3);

Entity newGroup = new Entity("group");
newGroup.setProperty("member", members);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download