Skip to content

Update Document - $pullAll

Function Build

Build the $pullAll update document using the generic PullAll function provided by the update package.

go
// bson.D{bson.E{Key:"$pullAll", Value:bson.D{bson.E{Key:"tags", Value:[]string{"old", "legacy"}}}}}
pullAll := update.PullAll("tags", "old", "legacy")

PullAll accepts a generic value list, so values with the same concrete type can be passed directly:

go
// bson.D{bson.E{Key:"$pullAll", Value:bson.D{bson.E{Key:"scores", Value:[]int{60, 70, 80}}}}}
pullAll := update.PullAll("scores", 60, 70, 80)
pullAll = update.PullAll("rates", 1.1, 1.2, 1.3)

Method Build (Builder)

Build the $pullAll update document using the Builder builder provided by the update package.

go
// bson.D{bson.E{Key:"$pullAll", Value:bson.D{bson.E{Key:"tags", Value:[]interface {}{"old", "legacy"}}}}}
pullAll := update.NewBuilder().PullAll("tags", "old", "legacy").Build()

In addition to the general PullAll method, the builder also provides specialized build methods for different data types. These methods follow the PullAll{Type} naming convention and are useful when the candidate value type is explicit.

MethodValue type
PullAllany
PullAllIntint
PullAllInt8int8
PullAllInt16int16
PullAllInt32int32
PullAllInt64int64
PullAllUintuint
PullAllUint8uint8
PullAllUint16uint16
PullAllUint32uint32
PullAllUint64uint64
PullAllFloat32float32
PullAllFloat64float64
PullAllStringstring

String values:

go
// bson.D{bson.E{Key:"$pullAll", Value:bson.D{bson.E{Key:"tags", Value:[]string{"old", "legacy"}}}}}
pullAll := update.NewBuilder().
    PullAllString("tags", "old", "legacy").
    Build()

Integer values:

go
// bson.D{bson.E{Key:"$pullAll", Value:bson.D{bson.E{Key:"scores", Value:[]int{60, 70, 80}}}}}
pullAll := update.NewBuilder().
    PullAllInt("scores", 60, 70, 80).
    Build()

Floating-point values:

go
// bson.D{bson.E{Key:"$pullAll", Value:bson.D{bson.E{Key:"rates", Value:[]float64{1.1, 1.2, 1.3}}}}}
pullAll := update.NewBuilder().
    PullAllFloat64("rates", 1.1, 1.2, 1.3).
    Build()

Use the general PullAll method when the value list is already []any, or when you need BSON values that are not covered by the typed helpers. In real updates, keep candidate values aligned with the array field element type.

go
// bson.D{bson.E{Key:"$pullAll", Value:bson.D{bson.E{Key:"tags", Value:[]any{"old", "legacy"}}}}}
values := []any{"old", "legacy"}

pullAll := update.NewBuilder().
    PullAll("tags", values...).
    Build()