Created
August 15, 2020 15:34
-
-
Save RouHim/bf752dda84c79aa2cfa2ebc9d4e7500e to your computer and use it in GitHub Desktop.
GO | ArangoDB | Return all documents of a collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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