1

Is there any way to implement below query in golang :

select * from test.demo in mapvalues where shopping_cart = "FL"

0

2 Answers 2

3

Check out the examples in the sandbox: https://developer.aerospike.com/client/usage/queries/basic/secondary

Here is the sample code for a range query on the canonical ufodata set in the sandbox (you would first have to create the secondary index of course):

// Create new query policy
queryPolicy := aerospike.NewQueryPolicy()
queryPolicy.FilterExpression = aerospike.ExpGeoCompare(
    aerospike.ExpGeoBin("location"), 
    aerospike.ExpGeoVal(region))

// Create statement
stmt := aerospike.NewStatement("sandbox", "ufodata")

// Create index filter
stmt.SetFilter(aerospike.NewRangeFilter("occurred", 20210101, 20211231))

// Execute the query
recordSet, err := client.Query(queryPolicy, stmt)

// Get the results
for records := range recordSet.Results() {
    if records != nil { 
        // Do something
        fmt.Printf("Record: %v \n", records.Record.Bins)
    }
}

recordSet.Close()

// Close the connection to the server
client.Close()
2
  • I tried this, but I'm getting nil data. I think this only executes normal query. select * from test.demo where shopping_cart = "FL" is getting executed I guess. mapvalues part is skipped. Also I have created a secondary index, and original query is giving me result on aql console
    – sid
    Jan 24 at 8:01
  • oh, I didn't realize the further details around mapvalues... I see you have posted a follow up here: discuss.aerospike.com/t/mapvalues-query-using-golang/9991. Let's see what comes up.
    – Meher
    Jan 25 at 23:06
0

You should be able to use the Aerospike client for Go. https://github.com/aerospike/aerospike-client-go

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.