Skip to content

Instantly share code, notes, and snippets.

@RouHim
Created August 15, 2020 15:34
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/bf752dda84c79aa2cfa2ebc9d4e7500e to your computer and use it in GitHub Desktop.
Save RouHim/bf752dda84c79aa2cfa2ebc9d4e7500e to your computer and use it in GitHub Desktop.
GO | ArangoDB | Return all documents of a collection
func GetAllDocuments(collectionName string) (foundDocuments []interface{}) {
ctx := driver.WithQueryCount(context.Background())
query := "FOR d IN " + collectionName + " RETURN d"
cursor, err := database.Query(ctx, query, nil)
if err != nil {
log.Fatal(err)
}
_ = cursor.Close()
foundDocuments = make([]interface{}, 0)
for {
var doc interface{}
_, err := cursor.ReadDocument(ctx, &doc)
if driver.IsNoMoreDocuments(err) {
break
} else if err != nil {
log.Fatal(err)
}
foundDocuments = append(foundDocuments, doc)
}
return foundDocuments
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment