Skip to content

Update

beanie.odm.operators.update.array

AddToSet

class AddToSet(BaseUpdateArrayOperator)

$addToSet update array query operator

Example:

class Sample(Document):
    results: List[int]

AddToSet({Sample.results: 2})

Will return query object like

{"$addToSet": {"results": 2}}

MongoDB docs: https://docs.mongodb.com/manual/reference/operator/update/addToSet/

Pop

class Pop(BaseUpdateArrayOperator)

$pop update array query operator

Example:

class Sample(Document):
    results: List[int]

Pop({Sample.results: 2})

Will return query object like

{"$pop": {"results": -1}}

MongoDB docs: https://docs.mongodb.com/manual/reference/operator/update/pop/

Pull

class Pull(BaseUpdateArrayOperator)

$pull update array query operator

Example:

class Sample(Document):
    results: List[int]

Pull(In(Sample.result: [1,2,3,4,5])

Will return query object like

{"$pull": { "results": { $in: [1,2,3,4,5] }}}

MongoDB docs: https://docs.mongodb.com/manual/reference/operator/update/pull/

Push

class Push(BaseUpdateArrayOperator)

$push update array query operator

Example:

class Sample(Document):
    results: List[int]

Push({Sample.results: 1})

Will return query object like

{"$push": { "results": 1}}

MongoDB docs: https://docs.mongodb.com/manual/reference/operator/update/push/

PullAll

class PullAll(BaseUpdateArrayOperator)

$pullAll update array query operator

Example:

class Sample(Document):
    results: List[int]

PullAll({ Sample.results: [ 0, 5 ] })

Will return query object like

{"$pullAll": { "results": [ 0, 5 ] }}

MongoDB docs: https://docs.mongodb.com/manual/reference/operator/update/pullAll/

beanie.odm.operators.update.general

Set

class Set(BaseUpdateGeneralOperator)

$set update query operator

Example:

class Sample(Document):
    one: int

Set({Sample.one: 2})

Will return query object like

{"$set": {"one": 2}}

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/set/

SetRevisionId

class SetRevisionId()

$set update query operator

Example:

class Sample(Document):
    one: int

Set({Sample.one: 2})

Will return query object like

{"$set": {"one": 2}}

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/set/

CurrentDate

class CurrentDate(BaseUpdateGeneralOperator)

$currentDate update query operator

Example:

class Sample(Document):
    ts: datetime

CurrentDate({Sample.ts: True})

Will return query object like

{"$currentDate": {"ts": True}}

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/currentDate/

Inc

class Inc(BaseUpdateGeneralOperator)

$inc update query operator

Example:

class Sample(Document):
    one: int

Inc({Sample.one: 2})

Will return query object like

{"$inc": {"one": 2}}

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/inc/

Min

class Min(BaseUpdateGeneralOperator)

$min update query operator

Example:

class Sample(Document):
    one: int

Min({Sample.one: 2})

Will return query object like

{"$min": {"one": 2}}

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/min/

Max

class Max(BaseUpdateGeneralOperator)

$max update query operator

Example:

class Sample(Document):
    one: int

Max({Sample.one: 2})

Will return query object like

{"$max": {"one": 2}}

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/max/

Mul

class Mul(BaseUpdateGeneralOperator)

$mul update query operator

Example:

class Sample(Document):
    one: int

Mul({Sample.one: 2})

Will return query object like

{"$mul": {"one": 2}}

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/mul/

Rename

class Rename(BaseUpdateGeneralOperator)

$rename update query operator

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/rename/

SetOnInsert

class SetOnInsert(BaseUpdateGeneralOperator)

$setOnInsert update query operator

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/setOnInsert/

Unset

class Unset(BaseUpdateGeneralOperator)

$unset update query operator

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/unset/

beanie.odm.operators.update.bitwise

Bit

class Bit(BaseUpdateBitwiseOperator)

$bit update query operator

MongoDB doc: https://docs.mongodb.com/manual/reference/operator/update/bit/