@@ -822,3 +822,94 @@ func (p *Pipeline) RawStage(name string, args []any, opts ...RawStageOptions) *P
822822 }
823823 return p .append (stage )
824824}
825+
826+ // UpdateOption is an option for an Update pipeline stage.
827+ //
828+ // Experimental: Firestore Pipelines is currently in preview and is subject to potential breaking changes in future versions,
829+ // regardless of any other documented package stability guarantees.
830+ type UpdateOption interface {
831+ isUpdateOption ()
832+ }
833+
834+ type updateTransformationsOption struct {
835+ fields []Selectable
836+ }
837+
838+ func (updateTransformationsOption ) isUpdateOption () {}
839+
840+ // WithUpdateTransformations specifies the list of field transformations to apply in an update operation.
841+ //
842+ // Experimental: Firestore Pipelines is currently in preview and is subject to potential breaking changes in future versions,
843+ // regardless of any other documented package stability guarantees.
844+ func WithUpdateTransformations (field Selectable , additionalFields ... Selectable ) UpdateOption {
845+ return updateTransformationsOption {
846+ fields : append ([]Selectable {field }, additionalFields ... ),
847+ }
848+ }
849+
850+ // Update performs an update operation using documents from previous stages.
851+ //
852+ // This method updates the documents in place based on the data flowing through the pipeline.
853+ // You can optionally specify a list of [Selectable] field transformations using [WithUpdateTransformations].
854+ // If no transformations are provided, it performs the update in-place without any changes.
855+ //
856+ // Example:
857+ //
858+ // // In-place update
859+ // client.Pipeline().Literals(updateData).Update()
860+ //
861+ // // Update with transformations
862+ // client.Pipeline().Collection("books").
863+ // Where(GreaterThan("price", 50)).
864+ // Update(WithUpdateTransformations(ConstantOf("Discounted").As("status")))
865+ //
866+ // Experimental: Firestore Pipelines is currently in preview and is subject to potential breaking changes in future versions,
867+ // regardless of any other documented package stability guarantees.
868+ func (p * Pipeline ) Update (opts ... UpdateOption ) * Pipeline {
869+ if p .err != nil {
870+ return p
871+ }
872+
873+ var transformations []Selectable
874+ for _ , opt := range opts {
875+ if opt != nil {
876+ switch o := opt .(type ) {
877+ case updateTransformationsOption :
878+ transformations = append (transformations , o .fields ... )
879+ }
880+ }
881+ }
882+
883+ stage , err := newUpdateStage (transformations )
884+ if err != nil {
885+ p .err = err
886+ return p
887+ }
888+ return p .append (stage )
889+ }
890+
891+ // DeleteOption is an option for a Delete pipeline stage.
892+ //
893+ // Experimental: Firestore Pipelines is currently in preview and is subject to potential breaking changes in future versions,
894+ // regardless of any other documented package stability guarantees.
895+ type DeleteOption interface {
896+ isDeleteOption ()
897+ }
898+
899+ // Delete deletes the documents from previous stages.
900+ //
901+ // Example:
902+ //
903+ // client.Pipeline().Collection("logs").
904+ // Where(Equal("status", "archived")).
905+ // Delete()
906+ //
907+ // Experimental: Firestore Pipelines is currently in preview and is subject to potential breaking changes in future versions,
908+ // regardless of any other documented package stability guarantees.
909+ func (p * Pipeline ) Delete (opts ... DeleteOption ) * Pipeline {
910+ if p .err != nil {
911+ return p
912+ }
913+ stage := newDeleteStage ()
914+ return p .append (stage )
915+ }
0 commit comments