What is a Document Query?

  • RavenDB Queries can be executed via query, document_query or directly using RQL.
    Learn more in Query Overview.
  • In the Python client API, query methods and their equivalent document_query methods provide the same functionality. (This is different from the C# client implementation, which often provides different functionality for Query methods and their DocumentQuery counterparts.)
    Therefore the Python documentation often provides query usage samples without adding document_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 = (
    .where_equals("Id", "employees/1-A")
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