UpdateOperator¶
-
class
UpdateOperator
(update)¶ UpdateOperators can be used to automatically generate update queries that are understood by mongo. Each of the operators can be used as defined in the mongo manual as they’re just a direct mapping.
Note
Please note that because of the overlap in keywords all these classes are capitalised!
Note
Makes use of write_bulk to enable the usage of multiple update operators to compress all changes to just on save call on the user side.
Set¶
-
class
Set
(update)¶ Is used to set the specified field to any given value. Not using it is the default case and functionally the same as just leaving out an UpdateOperator completely.
Example usage:
>>> doc.num = 5 >>> doc.num = Set(5)
Query:
>>> Set(5)() {'$set': 5}
Inc¶
Note
Like in mongo Inc can be used with positive and negative numbers. For continuity Dec can also be used and is used for implicit substraction.
-
class
Inc
(update)¶ Is used to modify a numeric value by a given amount.
Example usage:
>>> doc.num = Inc(5) >>> doc.num = Inc(-5)
Query:
>>> Inc(5)() {'$inc': 5}
-
class
Dec
(update)¶ Is used to decrease a numeric value.
Example usage:
>>> doc.num = Dec(5)
Query:
>>> Dec(5)() {'$inc': -5}
Max¶
-
class
Max
(update)¶ Update the field to the maximum of database and current value.
Example usage:
>>> doc.num = Max(5)
Query:
>>> Max(5)() {'$max': 5}
Min¶
-
class
Min
(update)¶ Update the field to the minimum of database and current value.
Example usage:
>>> doc.num = Min(5)
Query:
>>> Min(5)() {'$min': 5}
Mul¶
-
class
Mul
(update)¶ Is used to multipy a numeric value by a given amount.
Example usage:
>>> doc.num = Mul(5)
Query:
>>> Mul(5)() {'$mul': 5}
Push¶
-
class
Push
(update)¶ Is used to append a value to a list.
Example usage:
>>> doc.num_list = Push(5)
Query:
>>> Push(5)() {'$push': 5}