4
votes

I've an entity in Google Cloud Datastore. One of the properties is array of strings. For example:

property: skills

Entity 1:
value: ["mysql","sqlserver","postgresql","sqllite","sql-server-2008","sql"]

Entity 2:
value: ["css","css3"]

Now, I need to query for those entities that contain array elements css*

In typical SQL, it'll be select * from kindName where skills like 'css%'

I tried select * from kindName where skills = 'css', which works fine but how can I get entities that have css* elements similar to the SQL query?

Or

What's the best way to model the data for this?

1
Make sure to write css every time css3 is used? Or try queries by prefix, .e.g stackoverflow.com/questions/17702958/… - Dmytro Sadovnychyi

1 Answers

2
votes

You can do inequality range checks on a single indexed property as given in the example below. Range checks on strings are essentially how you can perform prefix searching on strings.

SELECT * from yourKind WHERE skills >= "css" AND skills < "cst"

As an example, here is the query performed on some sample data I created in the UI Console for Cloud Datastore:

Example performed in the Google Cloud Datastore's console