mongodb
insertOrUpdate
filter := bson.M{"_id": objectId}
update := bson.M{
"$set": bson.M{
"name": "Updated Name",
"age": 30,
},
}
opts := options.FindOneAndUpdate().
SetUpsert(true).
SetReturnDocument(options.After)
result := collection.FindOneAndUpdate(context.TODO(), filter, update, opts)
if err := result.Decode(&updatedDocument); err != nil {
log.Fatal(err)
}
fmt.Printf("Updated document: %+v\n", updatedDocument)
rabbitmq
生产者ack
conn.Confirm(false)
conn.Qos(1,0,false)
confirmations := ch.NotifyPublish(make(chan amqp091.Confirmation, 2))
utils.GoSafe(func() {
for c := range confirmations {
if !c.Ack {
glog.Errorf("message not acked: delivery tag: %d", c.DeliveryTag)
} else {
glog.Infof("message acked: delivery tag: %d", c.DeliveryTag)
}
}
})
···