This commit is contained in:
Florian Baumann 2021-12-28 09:56:13 +01:00
parent 33bb189860
commit 1574641742
2 changed files with 8 additions and 9 deletions

View File

@ -41,6 +41,9 @@ func List() {
client := storage_connect()
coll := client.Database("serra").Collection("cards")
storage_find(coll)
cards, _ := storage_find(coll)
for _, card := range cards {
fmt.Sprintf("%s %s", card.Name, card.Prices.Eur)
}
}

View File

@ -2,7 +2,6 @@ package serra
import (
"context"
"fmt"
"log"
"os"
@ -42,7 +41,7 @@ func storage_add(coll *mongo.Collection, card *Card) error {
}
func storage_find(coll *mongo.Collection) error {
func storage_find(coll *mongo.Collection) ([]Card, error) {
opts := options.Find().SetSort(bson.D{{"collectornumber", 1}})
cursor, err := coll.Find(context.TODO(), bson.D{{}}, opts)
@ -52,14 +51,11 @@ func storage_find(coll *mongo.Collection) error {
// Get a list of all returned documents and print them out.
// See the mongo.Cursor documentation for more examples of using cursors.
var results []bson.M
var results []Card
if err = cursor.All(context.TODO(), &results); err != nil {
log.Fatal(err)
return err
return []Card{}, err
}
for _, result := range results {
fmt.Println(result)
}
return nil
return results, nil
}