func (u *Update) Execute(ctx context.Context) error {
	if u.deployment == nil {
		return errors.New("the Update operation must have a Deployment set before Execute can be called")
	}
	batches := &driver.Batches{
		Identifier: "updates",
		Documents:  u.updates,
		Ordered:    u.ordered,
	}
	return driver.Operation{
		CommandFn:         u.command,
		ProcessResponseFn: u.processResponse,
		Batches:           batches,
		RetryMode:         u.retry,
		Type:              driver.Write,
		Client:            u.session,
		Clock:             u.clock,
		CommandMonitor:    u.monitor,
		Database:          u.database,
		Deployment:        u.deployment,
		Selector:          u.selector,
		WriteConcern:      u.writeConcern,
		Crypt:             u.crypt,
	}.Execute(ctx, nil)
}
Execute runs this operations and returns an error if the operaiton did not execute successfully.
package operation
import (
	"context"
	"errors"
	"fmt"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/event"
	"go.mongodb.org/mongo-driver/mongo/description"
	"go.mongodb.org/mongo-driver/mongo/writeconcern"
	"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
	"go.mongodb.org/mongo-driver/x/mongo/driver"
	"go.mongodb.org/mongo-driver/x/mongo/driver/session"
)
type Update struct {
	bypassDocumentValidation *bool
	ordered                  *bool
	updates                  []bsoncore.Document
	session                  *session.Client
	clock                    *session.ClusterClock
	collection               string
	monitor                  *event.CommandMonitor
	database                 string
	deployment               driver.Deployment
	hint                     *bool
	arrayFilters             *bool
	selector                 description.ServerSelector
	writeConcern             *writeconcern.WriteConcern
	retry                    *driver.RetryMode
	result                   UpdateResult
	crypt                    *driver.Crypt
}
type Upsert struct {
	Index int64
	ID    interface{} `bson:"_id"`
}
type UpdateResult struct {
	N int32
	NModified int32
	Upserted []Upsert
}
func buildUpdateResult(response bsoncore.Document, srvr driver.Server) (UpdateResult, error) {
	elements, err := response.Elements()
	if err != nil {
		return UpdateResult{}, err
	}
	ur := UpdateResult{}
	for _, element := range elements {
		switch element.Key() {
		case "nModified":
			var ok bool
			ur.NModified, ok = element.Value().Int32OK()
			if !ok {
				err = fmt.Errorf("response field 'nModified' is type int32, but received BSON type %s", element.Value().Type)
			}
		case "n":
			var ok bool
			ur.N, ok = element.Value().Int32OK()
			if !ok {
				err = fmt.Errorf("response field 'n' is type int32, but received BSON type %s", element.Value().Type)
			}
		case "upserted":
			arr, ok := element.Value().ArrayOK()
			if !ok {
				err = fmt.Errorf("response field 'upserted' is type array, but received BSON type %s", element.Value().Type)
				break
			}
			var values []bsoncore.Value
			values, err = arr.Values()
			if err != nil {
				break
			}
			for _, val := range values {
				valDoc, ok := val.DocumentOK()
				if !ok {
					err = fmt.Errorf("upserted value is type document, but received BSON type %s", val.Type)
					break
				}
				var upsert Upsert
				if err = bson.Unmarshal(valDoc, &upsert); err != nil {
					break
				}
				ur.Upserted = append(ur.Upserted, upsert)
			}
		}
	}
	return ur, nil
}
func NewUpdate(updates ...bsoncore.Document) *Update {
	return &Update{
		updates: updates,
	}
}
func (u *Update) Result() UpdateResult { return u.result }
func (u *Update) processResponse(response bsoncore.Document, srvr driver.Server, desc description.Server, currIndex int) error {
	ur, err := buildUpdateResult(response, srvr)
	u.result.N += ur.N
	u.result.NModified += ur.NModified
	if currIndex > 0 {
		for ind := range ur.Upserted {
			ur.Upserted[ind].Index += int64(currIndex)
		}
	}
	u.result.Upserted = append(u.result.Upserted, ur.Upserted...)
	return err
}