go – Not able to update data using golang mongodb-ThrowExceptions

Exception or error:
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
}
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *