go - 无法使用 golang mongodb 更新数据
问题描述
func (s *MongoClient) UpdateProduct(person models.Person)(*mongo.SingleResult) {
filter := bson.M{"_id": bson.M{"$eq": person.ID}}
update := bson.M{
"$set":bson.M{
"firstname": person.Firstname,
"lastname": person.Lastname,
},
}
collection := s.client.Database("thepolyglotdeveloper").Collection("group")
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
result:= collection.FindOneAndUpdate(ctx, filter,update)
return result
}
解决方案
推荐阅读
- vaadin - 如何在服务器端 Java 代码中获取 Vaadin 10 中的浏览器窗口宽度
- c - 在c中创建n个链表
- tensorflow - 如何在不使用导出和重新加载的情况下从 TF ODI 训练器中提取推理图?
- zend-studio - Zend Studio 问题添加 Zend Server - Windows 10
- android - 如何在Android Studio类上自动插入注释@Since
- haskell - TimeDuration 类型可以是 Semigroup 和 Monoid 的实例吗?
- angular - 如何将登录名与应用程序的其余部分分开?
- javascript - 如何在 JavaScript if/else 语句和 Bootstrap 4 下拉菜单中使用 innerHTML
- c# - C#如何获取字典的第一个元素并移动到另一个
- javascript - 我的插入方法不起作用