Queryset¶
-
class
yadm.queryset.
QuerySet
(db, document_class)¶ Query builder
-
bulk
()¶ Return map {id: object}
Returns: dict
-
copy
(*args, **kwargs)¶ Copy queryset and update it
Parameters: - criteria (dict) –
- projection (dict) –
- sort (dict) –
Returns: new
yadm.queryset.QuerySet
object
-
count
()¶ Count documents in queryset
Returns: int
-
distinct
(field)¶ Distinct query
Parameters: field (str) – field for distinct Returns: list with result data
-
fields
(*fields)¶ Get only setted fields
Update projection with fields.
Parameters: fields (str) – Returns: new yadm.queryset.QuerySet
qs('field', 'field2')
-
fields_all
()¶ Clear projection
-
find
(criteria=None, projection=None)¶ Return queryset copy with new criteria and projection
Parameters: - criteria (dict) – update queryset’s criteria
- projection (dict) – update queryset’s projection
Returns: qs({'field': {'$gt': 3}}, {'field': True})
-
find_and_modify
(update=None, upsert=False, full_response=False, new=False, **kwargs)¶ Execute $findAndModify query
Parameters: - update (dict) – see second argument to update()
- upsert (bool) – insert if object doesn’t exist (default False)
- full_response (bool) – return the entire response object from the server (default False)
- new – return updated rather than original object (default False)
- kwargs – any other options the findAndModify command supports can be passed here
Returns: yadm.documents.Document
or None
-
find_one
(criteria=None, projection=None)¶ Find and return only one document
Parameters: - criteria (dict) – update queryset’s criteria
- projection (dict) – update queryset’s projection
Returns: yadm.documents.Document
or Noneqs({'field': {'$gt': 3}}, {'field': True})
-
join
(*field_names)¶ Create yadm.Join object, join field_names and return it
Parameters: fiels_names (str) – fields for join Returns: new yadm.join.Join
- Next algorithm for join:
- Get all documents from queryset;
- Aggegate all ids from requested fields;
- Make $in queries for get joined documents;
- Bind joined documents to objects from first queryset;
Join object is instance of abc.Sequence.
-
remove
()¶ Remove documents in queryset
-
sort
(*sort)¶ Sort query
Parameters: sort (tuples) – tuples with two items: (‘field_name’, sort_order_as_int). qs.sort(('field_1', 1), ('field_2', -1))
-
update
(update, multi=True)¶ Update documents in queryset
Parameters: - update (dict) – update query
- multi (bool) – update all matched documents (default True)
Returns: update result
-
with_id
(_id)¶ Find document with id
Parameters: _id – id of searching document Returns: yadm.documents.Document
or None
-