from beanie.odm.operators.update import BaseUpdateOperator class BaseUpdateArrayOperator(BaseUpdateOperator): operator = "" def __init__(self, expression): self.expression = expression @property def query(self): return {self.operator: self.expression} class AddToSet(BaseUpdateArrayOperator): """ `$addToSet` update array query operator Example: ```python class Sample(Document): results: List[int] AddToSet({Sample.results: 2}) ``` Will return query object like ```python {"$addToSet": {"results": 2}} ``` MongoDB docs: """ operator = "$addToSet" class Pop(BaseUpdateArrayOperator): """ `$pop` update array query operator Example: ```python class Sample(Document): results: List[int] Pop({Sample.results: 2}) ``` Will return query object like ```python {"$pop": {"results": -1}} ``` MongoDB docs: """ operator = "$pop" class Pull(BaseUpdateArrayOperator): """ `$pull` update array query operator Example: ```python class Sample(Document): results: List[int] Pull(In(Sample.result: [1,2,3,4,5]) ``` Will return query object like ```python {"$pull": { "results": { $in: [1,2,3,4,5] }}} ``` MongoDB docs: """ operator = "$pull" class Push(BaseUpdateArrayOperator): """ `$push` update array query operator Example: ```python class Sample(Document): results: List[int] Push({Sample.results: 1}) ``` Will return query object like ```python {"$push": { "results": 1}} ``` MongoDB docs: """ operator = "$push" class PullAll(BaseUpdateArrayOperator): """ `$pullAll` update array query operator Example: ```python class Sample(Document): results: List[int] PullAll({ Sample.results: [ 0, 5 ] }) ``` Will return query object like ```python {"$pullAll": { "results": [ 0, 5 ] }} ``` MongoDB docs: """ operator = "$pullAll"