Update Expressions¶
Updates are done by calling any of the update operations on a query object
-
class
ommongo.update_expression.
UpdateExpression
(query)¶ -
add_to_set
(qfield, value)¶ Atomically add
value
toqfield
. The field represented byqfield
must be a setNote
Requires server version 1.3.0+.
-
append
(qfield, value)¶ Atomically append
value
toqfield
. The operation will if the field is not a list field
-
execute
()¶ Execute the update expression on the database
-
extend
(qfield, *value)¶ Atomically append each value in
value
to the fieldqfield
-
inc
(*args, **kwargs)¶ Atomically increment
qfield
byvalue
-
multi
()¶ Update multiple documents. The Mongo default is to only update the first matching document
-
pop_first
(qfield)¶ Atomically pop the first item in
qfield.
.. note:: Requires version 1.1+
-
pop_last
(qfield)¶ Atomically pop the last item in
qfield.
.. note:: Requires version 1.1+
-
remove
(qfield, value)¶ Atomically remove
value
fromqfield
-
remove_all
(qfield, *value)¶ Atomically remove each value in
value
fromqfield
-
safe
(safe=True)¶ Mark the query as a “safe” query with pymongo.
Parameters: safe – Defaults to True. Force “safe” on or off
-
set
(*args, **kwargs)¶ Usage is either:
set(self, qfield, value): Atomically set
qfield
tovalue
OR
set(key1=value1, key2=value2): Atomically set the named arguments on the current object to the values given. This form cannot update a sub-document
-
unset
(qfield)¶ Atomically delete the field
qfield
.. note:: Requires server version >= 1.3.0+.
-
upsert
()¶ If a document matching the query doesn’t exist, create one
-
Remove Queries¶
Remove queries are executed with the remove_query
method on a session.
They have the same filtering methods as querying.
-
class
ommongo.query.
RemoveQuery
(type, session)¶ Execute a remove query to remove the matched objects from the database
Parameters: - type – A subclass of class:ommongo.document.Document
- db – The
Session
which this query is associated with.
-
execute
()¶ Run the remove command on the session. Return the result of
getLastError
ifsafe
isTrue
-
filter
(*query_expressions)¶ Filter the remove expression with
*query_expressions
, as in theQuery
filter method.
-
filter_by
(**filters)¶ Filter for the names in
filters
being equal to the associated values. Cannot be used for sub-objects since keys must be strings
-
in_
(qfield, *values)¶ Works the same as the query expression method
in_
-
nin
(qfield, *values)¶ Works the same as the query expression method
nin_
-
or_
(first_qe, *qes)¶ Works the same as the query expression method
or_
-
query
¶
-
set_safe
(is_safe, **kwargs)¶ Set this remove to be safe. It will call getLastError after the remove to make sure it was successful.
**kwargs
are parameters to MongoDB’s getLastError command (as in pymongo’s remove).
Find and Modify¶
Find and modify is done by calling find_and_modify on a query object
-
class
ommongo.update_expression.
FindAndModifyExpression
(query, new, remove)¶ -
add_to_set
(qfield, value)¶ Atomically add
value
toqfield
. The field represented byqfield
must be a setNote
Requires server version 1.3.0+.
-
append
(qfield, value)¶ Atomically append
value
toqfield
. The operation will if the field is not a list field
-
execute
()¶ Execute the find and modify expression on the database
-
extend
(qfield, *value)¶ Atomically append each value in
value
to the fieldqfield
-
inc
(*args, **kwargs)¶ Atomically increment
qfield
byvalue
-
multi
()¶ Update multiple documents. The Mongo default is to only update the first matching document
-
pop_first
(qfield)¶ Atomically pop the first item in
qfield.
.. note:: Requires version 1.1+
-
pop_last
(qfield)¶ Atomically pop the last item in
qfield.
.. note:: Requires version 1.1+
-
remove
(qfield, value)¶ Atomically remove
value
fromqfield
-
remove_all
(qfield, *value)¶ Atomically remove each value in
value
fromqfield
-
safe
(safe=True)¶ Mark the query as a “safe” query with pymongo.
Parameters: safe – Defaults to True. Force “safe” on or off
-
set
(*args, **kwargs)¶ Usage is either:
set(self, qfield, value): Atomically set
qfield
tovalue
OR
set(key1=value1, key2=value2): Atomically set the named arguments on the current object to the values given. This form cannot update a sub-document
-
unset
(qfield)¶ Atomically delete the field
qfield
.. note:: Requires server version >= 1.3.0+.
-
upsert
()¶ If a document matching the query doesn’t exist, create one
-