From 222d0d5a4d8cbce00b9a8316895353b925683e0b Mon Sep 17 00:00:00 2001 From: Florian Baumann Date: Fri, 31 Dec 2021 10:51:04 +0100 Subject: [PATCH] update --- src/serra/root.go | 8 ++++++++ src/serra/storage.go | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/serra/root.go b/src/serra/root.go index e774702..dc3a2f9 100644 --- a/src/serra/root.go +++ b/src/serra/root.go @@ -90,6 +90,14 @@ func Update() { for _, card := range cards { fmt.Printf("%s (%s) %.2f\n", card.Name, card.Set, card.Prices.Eur) + + // db.cards.update({'_id':'8fa2ecf9-b53c-4f1d-9028-ca3820d043cb'},{$set:{'serra_updated':ISODate("2021-11-02T09:28:56.504Z")}, $push: {"serra_prices": { date: ISODate("2021-11-02T09:28:56.504Z"), value: 0.1 }}}); + + // Declare an _id filter to get a specific MongoDB document + filter := bson.M{"_id": bson.M{"$eq": card.ID}} + + // Declare a filter that will change a field's integer value to `42` + update := bson.M{"$set": bson.M{"textless": true}} } storage_disconnect(client) diff --git a/src/serra/storage.go b/src/serra/storage.go index fc98ac9..0db85be 100644 --- a/src/serra/storage.go +++ b/src/serra/storage.go @@ -2,6 +2,7 @@ package serra import ( "context" + "fmt" "log" "os" "time" @@ -78,6 +79,24 @@ func storage_aggregate(coll *mongo.Collection, groupstage bson.D) ([]primitive.M } +func storage_update(coll *mongo.Collection, filter, update bson.M) ([]primitive.M, error) { + + // Call the driver's UpdateOne() method and pass filter and update to it + result, err := col.UpdateOne( + context.Background(), + filter, + update, + ) + if err != nil { + log.Fatal(err) + } + fmt.Println(result) + + // Get a list of all returned documents and print them out. + // See the mongo.Cursor documentation for more examples of using cursors. + +} + func storage_disconnect(client *mongo.Client) error { if err := client.Disconnect(context.TODO()); err != nil { return err