首页 > 解决方案 > 无法使用 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
}

标签: go

解决方案


推荐阅读