---
title: "Run Simple and Compound Queries on a Collection"
method: POST
path: "/api/collections/data/fetch/query"
tags: ["Database Management"]
---

# Run Simple and Compound Queries on a Collection

`POST /api/collections/data/fetch/query`

Run Simple and Compound Queries on a Collection. You can run a simple `WHERE` query or a compound `AND` or `OR` query on a Collection. This is useful when you want to fetch a specific Document from a Collection and perform some operations on it. You can also sort the response in a specific order of `asc` or `desc` on the basis of the Field/Key that you pass in and limit the number of Documents that you want to fetch.

## Request body

- object
  - `collection` string — The Name of the Collection or the Group where you want to store all your data.
  - `queries` object[] — The Queries that you want to run on the Collection. You can run a simple `WHERE` query or a compound `AND` or `OR` using the `join` query parameter on a Collection.
    - `field` string — The Field/Key that you want to run the query on.
    - `operator` '<' | '<=' | '==' | '>' | '>=' | '!=' | 'less than' | 'less than or equal to' | 'equal to' | 'greater than' | 'greater than or equal to' | 'not equal to' — The Operator that you want to run the query with. This is optional. By default we will run the query with the `==` operator. If you add a `operator` Field/Key, we will run the query with that Operator.
    - `value` string — The Value that you want to run the query with. This is optional. By default we will run the query with the `==` operator. If you add a `value` Field/Key, we will run the query with that Value.
  - `compounding` 'and' | 'or' — The Compounding Operator that you want to run the query with. This is optional. By default we will run the query with the `and` operator if you pass multiple queries. If you add a `compounding` parameter, we will run the query with that Compounding Operator.
  - `orderBy` string — The Field/Key that you want to sort the response by. This is optional. By default we will sort it by the Field/Key that you pass in as default orderBy value when collection was created. If you add a `orderBy` Field/Key, we will sort the response by that Field/Key.
  - `orderType` 'asc' | 'desc' — The Order Type that you want to sort the response by. This is optional. By default we will sort it in `asc` order. If you add a `orderType` Field/Key, we will sort the response by that Order Type on the `orderBy` Field/Key.
  - `limit` integer — The Limit of the number of Documents that you want to fetch. This is optional. By default we will fetch all the Documents that match the query. If you add a `limit` Field/Key, we will limit the response by that number.
  - `startAfter` string — The number of documents to skip. This is optional. By default we will not skip any documents. If you add a `startAfter` value, we will skip the number of documents that you pass in.
  - `outputType` 'json' | 'stream' | 'file' — The type of output you want. `json` will return the data as a JSON object that is parseable. `stream` will return the data as a stream of data and `file` will return the data as a parseable CSV file.

## Response `200`

Output from the Database Collection Fetch Process

- object
  - `status` string — Status indicating the success of the text moderation.
  - `processing_time` integer — The time taken to process the request, in milliseconds.
  - `processing_id` string — A universally unique identifier for the request. This can be used to track the request in the logs.
  - `processing_count` integer — The number of times the request has been processed. This is what is considered in the Billing Process. This is either the number of times the image is processed or the number of words that the server processes.
  - `data` object
    - `databaseId` string — The ID of the Database where the data is stored.
    - `collection` string — The Name of the Collection or the Group where you want to store all your data.
    - `elapsed_time` integer — The time taken to process the request, in milliseconds.
    - `data` object[]
      - `sampleDbContent` string — The data that is stored in the Collection.
      - `sampleDbContent2` string — The data that is stored in the Collection.

## Other responses

- `400` — Bad Request.
- `401` — Unauthorized
- `404` — Not Found
- `406` — Not Acceptable
- `500` — Internal Server Error

---

[API](https://skmtc.net/worqhat/apis/worqhat-ai-api-endpoints-2.md) · [All operations](https://skmtc.net/worqhat/apis/worqhat-ai-api-endpoints-2/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/worqhat/worqhat-ai-api-endpoints-2/versions/fc369f69a3e6/schema)
