Narendar
Narendar

Reputation: 370

Query on Array of strings to get matched values from Datastore

I have following scenario where struct is

type Band struct {
Name       string  `json:"name"`
Albums     []String `json:"album"`
GradeLevel []string   `json:"gradeLevel,omitempty"`
Topics     []string   `json:"topics,omitempty"`

}

Data stored like (Sample)

**Name          Albums           GradeLevel               Topics**
Sample   ["sample","Test"]      ["grade1"]         ["Children","Poems"]
test        ["Test"]        ["grade2","grade1"]      ["therapy","slow"]

Here how to query to get appropriate values from Band kind with given inputs like Request to query is {"album" : ["sample","Test"] , "gradeLevel" : ["grade1"] , "topic" : ["poem"]}

With combination of inputs are possible from front-end so how to query based input to display list of values for above scenario.

Upvotes: 1

Views: 821

Answers (1)

Rajeevan
Rajeevan

Reputation: 150

You can find information on writing queries in Go to retrieve data from Firestore in Datastore mode here [1]. To query if an array contains a value, you need to use an equality filter [2].

[1] https://cloud.google.com/datastore/docs/concepts/queries

[2] https://cloud.google.com/datastore/docs/concepts/queries#array_values

Upvotes: 1

Related Questions