update
This commit is contained in:
parent
5f30f98d48
commit
222d0d5a4d
@ -90,6 +90,14 @@ func Update() {
|
|||||||
|
|
||||||
for _, card := range cards {
|
for _, card := range cards {
|
||||||
fmt.Printf("%s (%s) %.2f\n", card.Name, card.Set, card.Prices.Eur)
|
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)
|
storage_disconnect(client)
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package serra
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"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 {
|
func storage_disconnect(client *mongo.Client) error {
|
||||||
if err := client.Disconnect(context.TODO()); err != nil {
|
if err := client.Disconnect(context.TODO()); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user