Skip to content

Instantly share code, notes, and snippets.

@RouHim
Created August 15, 2020 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RouHim/439b2d56fd29989d3a1f44322bc38ce4 to your computer and use it in GitHub Desktop.
Save RouHim/439b2d56fd29989d3a1f44322bc38ce4 to your computer and use it in GitHub Desktop.
GO | ArangoDB | Retrieve typed documents for a query with a parameter
func RetrieveDocumentsForDate(date string) {
ctx := context.Background()
query := "FOR d IN table FILTER d.date == @date RETURN d"
bindVars := map[string]interface{}{
"date": date,
}
cursor, err := database.Query(ctx, query, bindVars)
if err != nil {
log.Fatal(err)
}
_ = cursor.Close()
for {
var doc meal.Meal
_, err := cursor.ReadDocument(ctx, &doc)
if driver.IsNoMoreDocuments(err) {
break
} else if err != nil {
// handle other errors
}
fmt.Printf("Got doc with key '%s' from query\n", doc.Name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment