A query object has all of the methods necessary to programmatically generate a mongo query as well as methods to retrieve results of the query or do an update based on it.
In general a query object should be created via Session.query, not directly.
Parameters: |
|
---|
The mongo query object which would be executed if this Query object were used
Turns on raw output, meaning that the MongoAlchemy ORM layer is skipped and the results from pymongo are returned. Useful if you want to use the query functionality without getting python objects back
Sets the limit on the number of documents returned
Parameters: | limit – the number of documents to return |
---|
Sets the number of documents to skip in the result
Parameters: | skip – the number of documents to skip |
---|
Creates a clone of the current query and all settings. Further updates to the cloned object or the original object will not affect each other
Execute the query and return one result. If more than one result is returned, raises a BadResultException
Execute the query and return the first result. Unlike one, if there are multiple documents it simply returns the first one. If there are no documents, first returns None
Applies a hint for the query that it should use a (qfield, ASCENDING) index when performing the query.
Parameters: | qfield – the instance of mongoalchemy.QueryField to use as the key. |
---|
Applies a hint for the query that it should use a (qfield, DESCENDING) index when performing the query.
Parameters: | qfield – the instance of mongoalchemy.QueryField to use as the key. |
---|
Executes an explain operation on the database for the current query and returns the raw explain object returned.
Return all of the results of a query in a list
Execute this query and return all of the unique values of key.
Parameters: | key – the instance of mongoalchemy.QueryField to use as the distinct key. |
---|
Apply the given query expressions to this query object
Example: s.query(SomeObj).filter(SomeObj.age > 10, SomeObj.blood_type == 'O')
Parameters: | query_expressions – Instances of mongoalchemy.query_expression.QueryExpression |
---|
See also
QueryExpression class
Filter for the names in filters being equal to the associated values. Cannot be used for sub-objects since keys must be strings
Execute a count on the number of results this query would return.
Parameters: | with_limit_and_skip – Include .limit() and .skip() arguments in the count? |
---|
Only return the specified fields from the object. Accessing a field that was not specified in fields will result in a :class:mongoalchemy.document.FieldNotRetrieved exception being raised
Parameters: | fields – Instances of :class:mongoalchemy.query.QueryField specifying which fields to return |
---|
Sort the result based on qfield in ascending order. These calls can be chained to sort by multiple fields.
Parameters: | qfield – Instance of :class:mongoalchemy.query.QueryField specifying which field to sort by. |
---|
Sort the result based on qfield in ascending order. These calls can be chained to sort by multiple fields.
Parameters: | qfield – Instance of :class:mongoalchemy.query.QueryField specifying which field to sort by. |
---|
pymongo-style sorting. Accepts a list of tuples.
Parameters: | sort_tuples – varargs of sort tuples. |
---|
Add a $not expression to the query, negating the query expressions given.
Examples: query.not_(SomeDocClass.age <= 18) becomes {'age' : { '$not' : { '$gt' : 18 } }}
Parameters: | query_expressions – Instances of mongoalchemy.query_expression.QueryExpression |
---|
Add a $not expression to the query, negating the query expressions given. The | operator on query expressions does the same thing
Examples: query.or_(SomeDocClass.age == 18, SomeDocClass.age == 17) becomes {'$or' : [{ 'age' : 18 }, { 'age' : 17 }]}
Parameters: | query_expressions – Instances of mongoalchemy.query_expression.QueryExpression |
---|
Check to see that the value of qfield is one of values
Parameters: |
|
---|
Check to see that the value of qfield is not one of values
Parameters: |
|
---|
The mongo “find and modify” command. Behaves like an update expression in that “execute” must be called to do the update and return the results.
Parameters: |
|
---|
Refer to: remove_all()
Refer to: add_to_set()
Refer to: pop_first()
Refer to: pop_last()