What is a Document Query?
- RavenDB Queries can be executed via
query
,document_query
or directly usingRQL
.
Learn more in Query Overview. -
In the Python client API,
query
methods and their equivalentdocument_query
methods provide the same functionality. (This is different from the C# client implementation, which often provides different functionality forQuery
methods and theirDocumentQuery
counterparts.)
Therefore the Python documentation often providesquery
usage samples without addingdocument_query
examples as well. -
In this page:
document_query
Examples
Query collection - no filtering
all_employees = list(session.advanced.document_query(object_type=Employee))
from "Employees"
Query collection - by ID
# Query collection by document ID
employee = (
session.advanced.document_query(object_type=Employee)
.where_equals("Id", "employees/1-A")
.first()
)
from "Employees" where id() == "employees/1-A"
Query collection - with filtering
# Query collection - filter by document field
employees = list(
session.advanced.document_query(object_type=Employee).where_equals("first_name", "Robert")
)
from "Employees" where FirstName == "Robert"
Query collection - with paging
# Query collection - page results
products = list(session.advanced.document_query(object_type=Product).skip(5).take(10))
from "Products" limit 5, 10 // skip 5, take 10
Query an index
Please refer to Querying an index for examples of querying an index using document_query.
Convert between document_query
and query
A document_query
can be converted to a query
.
# Define a document_query
doc_query = session.advanced.document_query(object_type=Order) # 'document_query' instance
query_results = list(doc_query.where_greater_than("freight", 25))
from "Orders" where Freight > 25
Available Custom Methods and Extensions
- add_or_der
- [query] after_query_executed
- [query] after_stream_executed
- [query] aggregate_by
- [query] aggregate_using
- and_also
- [query] before_query_executed
- boost
- close_subclause
- cmp_xchg
- contains_all
- contains_any
- count
- count_lazily
- distinct
- explain_scores
- first
- first_or_default
- fuzzy
- get_index_query
- get_query_result
- group_by
- group_by_array_values
- group_by_array_content
- [query] highlight
- include
- include_explanations
- intersect
- invoke_after_query_executed
- invoke_after_stream_eExecuted
- [query] lazily
- long_count
- more_like_this
- negate_next
- not
- [query] no_caching
- [query] no_tracking
- of_type
- open_subclause
- order_by
- order_by_descending
- [query] order_by_distance
- [query] order_by_distance_descending
- order_by_score
- order_by_score_descending
- or_else
- [query] projection
- proximity
- [query] random_ordering
- [query] relates_to_shape
- search
- select_fields
- select_time_series
- single
- single_or_default
- skip
- [query] spatial
- statistics
- suggest_using
- take
- [query] timings
- using_default_operator
- [query] wait_for_non_stale_results
- where
- WhereBetween
- where_ends_with
- where_equals
- where_exists
- where_greater_than
- where_greater_than_or_equal
- where_in
- where_less_than
- where_less_than_or_equal
- where_lucene
- where_not_equals
- where_regex
- where_starts_with
- within_radius_of