> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ditto.live/llms.txt
> Use this file to discover all available pages before exploring further.

# Find docs with Legacy QL

> Query documents in a collection using a flexible query language. This endpoint supports pagination, sorting, and complex queries to help you efficiently retrieve exactly the data you need.

<Warning>
  This is a legacy endpoint that uses the [Legacy Query Language](/dql/query-syntax-legacy).

  To use [DQL](/dql), the current Ditto query language, consider using the [execute](./post-storeexecute) endpoint.
</Warning>


## OpenAPI

````yaml post /store/find
openapi: 3.0.3
info:
  title: Ditto HTTP RPC API
  version: 4.0.0
  description: >-
    The Ditto HTTP RPC API provides a RESTful interface for interacting with
    Ditto's distributed data store. It enables you to query, insert, update and
    delete data across your Ditto network while maintaining strong consistency
    guarantees.
servers:
  - url: '{base_url}/api/v4'
    description: >-
      The Ditto Big Peer acts as a central synchronization point and data store
      in your Ditto network. It coordinates data replication between peers and
      provides a consistent view of your data.
    variables:
      base_url:
        default: https://REPLACE_WITH_MY_APP_ID.cloud.ditto.live
        description: >-
          Your unique Ditto application endpoint URL, found in the Ditto Portal
          under Application Settings. Replace REPLACE_WITH_MY_APP_ID with your
          actual app ID.
security:
  - api_key_or_jwt_token: []
externalDocs:
  url: https://docs.ditto.live/http/installation/
  description: >-
    For more detailed instructions on how to use this API and the Ditto SDK,
    please see the documentation.
paths:
  /store/find:
    post:
      description: >-
        Query documents in a collection using a flexible query language. This
        endpoint supports pagination, sorting, and complex queries to help you
        efficiently retrieve exactly the data you need.
      operationId: find_endpoint
      parameters:
        - name: X-DITTO-TXN-ID
          in: header
          description: >-
            Optional transaction ID that ensures read consistency. The operation
            will only proceed if the Big Peer's transaction ID is at least this
            value, preventing reads of stale data.
          required: false
          deprecated: false
          schema:
            type: integer
            format: int64
      requestBody:
        description: >-
          Specify the collection to query, the query conditions, and optional
          parameters like limit, offset, and sort order. The query can be
          parameterized using the args field for safe and efficient execution.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FindRequest'
        required: true
      responses:
        '200':
          description: >-
            The query executed successfully. Returns an array of matching
            documents and the transaction ID of the read operation. If no
            documents match, the documents array will be empty.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FindResponse'
            application/cbor:
              schema:
                $ref: '#/components/schemas/FindResponse'
        '400':
          description: >-
            The request was invalid. This could be due to malformed query
            syntax, invalid collection name, or invalid parameter values. Check
            the error message for details on how to correct the request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RpcError'
            application/cbor:
              schema:
                $ref: '#/components/schemas/RpcError'
        '401':
          description: >-
            Authentication failed. Verify that you're providing a valid API key
            or JWT token and that it has appropriate read permissions for the
            requested collection.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RpcError'
            application/cbor:
              schema:
                $ref: '#/components/schemas/RpcError'
        '500':
          description: >-
            An unexpected server error occurred. This could be due to resource
            constraints or internal errors. The request may succeed if retried
            after a brief delay.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RpcError'
            application/cbor:
              schema:
                $ref: '#/components/schemas/RpcError'
      deprecated: false
components:
  schemas:
    FindRequest:
      type: object
      description: >-
        Request parameters for querying documents in a collection. Supports
        filtering, pagination, and sorting to help you retrieve exactly the data
        you need.
      required:
        - collection
        - query
      properties:
        args:
          $ref: '#/components/schemas/AnyValue'
          description: >-
            Named parameters to use in the query, providing safe value
            substitution and better query performance
        collection:
          type: string
          description: The name of the collection to query
        describe:
          type: boolean
          default: false
          description: When true, includes additional metadata about the query execution
        formatAttachment:
          type: boolean
          default: false
          description: When true, formats any attachment fields for easier consumption
        limit:
          type: integer
          format: int32
          description: >-
            Maximum number of documents to return. Use with offset for
            pagination.
          default: 1000
        offset:
          type: integer
          format: int32
          description: >-
            Number of documents to skip before starting to return results. Use
            with limit for pagination.
        query:
          type: string
          description: >-
            The query expression that filters which documents to return. Use
            parameterized values with :param syntax for better security and
            performance.
        serializedAs:
          $ref: '#/components/schemas/SerializedAs'
          description: Controls how the document data is serialized in the response
        sort:
          type: array
          items:
            $ref: '#/components/schemas/Sort'
          description: Specifies the order in which to return matching documents
      example:
        collection: people
        query: favoriteBook.title == 'The Great Gatsby'
    FindResponse:
      type: object
      required:
        - documents
      properties:
        documents:
          type: array
          items:
            $ref: '#/components/schemas/Document'
          description: Array of documents matching the query criteria
        txnId:
          type: integer
          format: int64
          description: The transaction ID at which this query was performed
      example:
        documents:
          id: 1
          contents:
            name: Francis
            favoriteBook:
              title: The Great Gatsby
              published: 1925
        txnId: 9000
    RpcError:
      type: object
      description: Error response returned when an API request fails
      required:
        - message
      properties:
        message:
          type: string
          description: Human-readable description of what went wrong
      example:
        message: Some kind of human readable description of the error
    AnyValue: {}
    SerializedAs:
      type: string
      description: Controls how document values are serialized in responses
      default: latestValues
      enum:
        - latestValues
        - latestValuesAndTypes
    Sort:
      type: object
      description: Specifies how to sort query results by a property
      required:
        - property
        - direction
      properties:
        direction:
          $ref: '#/components/schemas/Direction'
          description: Sort direction (ascending or descending)
        property:
          type: string
          description: Document property to sort by
    Document:
      type: object
      description: >-
        Represents a document in the Ditto store. Documents are schema-free and
        can contain nested fields of various CRDT types for conflict-free
        replication.
      required:
        - id
        - fields
      properties:
        fields:
          $ref: '#/components/schemas/AnyValue'
          description: >-
            The document's content, which can include any valid JSON data types
            and special Ditto CRDT types
        id:
          $ref: '#/components/schemas/AnyValue'
          description: The unique identifier for this document within its collection
    Direction:
      type: string
      description: >-
        Sort direction for query results. Use 'asc' for ascending order (A to Z,
        1 to 9) or 'desc' for descending order (Z to A, 9 to 1).
      enum:
        - asc
        - desc
  securitySchemes:
    api_key_or_jwt_token:
      type: http
      scheme: bearer
      bearerFormat: API Key or JWT
      description: >-
        Authentication using either an API key or JWT token in the Authorization
        header

````