2024-05-31 14:31:27 +00:00
---
id: couchdb
title: CouchDB
---
2024-09-17 10:51:49 +00:00
ToolJet can connect to CouchDB databases to read and write data.
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< div style = {{paddingTop:'24px'}} >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
## Connection
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
To establish a connection with the CouchDB data source, you can either click on the ** + Add new Data source** button located on the query panel or navigate to the ** [Data Sources ](/docs/data-sources/overview )** page through the ToolJet dashboard.
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
ToolJet requires the following to connect to your CouchDB.
- **Username**
- **Password**
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/connections.png" alt = "Couch listing" / >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< / div >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< div style = {{paddingTop:'24px'}} >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
## Querying CouchDB
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
1. Click on ** + Add** button of the query manager at the bottom panel of the editor.
2. Select the **CouchDB** datasource added in previous step.
3. Select the operation you want to perform and enter the query.
4. Click on the **Preview** button to preview the output or Click on the **Run** button to create and trigger the query.
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/operations.png" alt = "Couch listing" / >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< / div >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< div style = {{paddingTop:'24px'}} >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
## Supported Queries
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
- **[List Records](#list-records)**
- **[Retrieve Record](#retrieve-record)**
- **[Create Record](#create-record)**
- **[Update Record](#update-record)**
- **[Delete Record](#delete-record)**
- **[Find](#find)**
- **[Get View](#get-view)**
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
### List Records
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
This query lists all the records in a database.
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
#### Optional Parameters
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
- **Include docs**
- **Descending order**
- **Limit**
- **Skip**
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/listing-v2.png" alt = "Couch listing" / >
2025-03-21 07:57:24 +00:00
< details id = "tj-dropdown" >
2024-09-17 10:51:49 +00:00
< summary > **Response Example**< / summary >
```json
2024-05-31 14:31:27 +00:00
{
"total_rows": 3,
"offset": 0,
"rows": [
{
"id": "23212104e60a71edb42ebc509f000dc2",
"key": "23212104e60a71edb42ebc509f000dc2",
"value": {
"rev": "1-0cc7f48876f15883394e5c139c628123"
}
},
{
"id": "23212104e60a71edb42ebc509f00216e",
"key": "23212104e60a71edb42ebc509f00216e",
"value": {
"rev": "1-b3c45696b10cb08221a335ff7cbd8b7a"
}
},
{
"id": "23212104e60a71edb42ebc509f00282a",
"key": "23212104e60a71edb42ebc509f00282a",
"value": {
"rev": "1-da5732beb913ecbded309321cac892d2"
}
},
]
}
```
2024-09-17 10:51:49 +00:00
< / details >
### Retrieve Record
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
This operation fetches a single record by its record ID.
2024-05-31 14:31:27 +00:00
#### Required Parameters:
- **Record ID**
2024-09-17 10:51:49 +00:00
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/retrieving-v2.png" alt = "Couch retrieve view" / >
2024-05-31 14:31:27 +00:00
2025-03-21 07:57:24 +00:00
< details id = "tj-dropdown" >
2024-09-17 10:51:49 +00:00
< summary > **Response Example** </ summary >
2024-05-31 14:31:27 +00:00
```json
{
"_id": "e33dc4e209689cb0400d095fc401a1e0",
"_rev": "1-a62af8e14451af88c150e7e718b7a0e8",
"0": {
"name": "test data"
}
}
```
2024-09-17 10:51:49 +00:00
< / details >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
### Create Record
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
Inserts a new record into the database.
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
#### Required Parameters:
- **Records**
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/creating-v2.png" alt = "Couch create view" / >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
#### Example
2024-05-31 14:31:27 +00:00
```json
[{"name":"tooljet"}]
```
2025-03-21 07:57:24 +00:00
< details id = "tj-dropdown" >
2024-09-17 10:51:49 +00:00
< summary > **Response Example**< / summary >
```json
{
"ok": true,
"id": "23212104e60a71edb42ebc509f0049a2",
"rev": "1-b0a625abc4e21ee554737920156e911f"
}
```
< / details >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
### Update Record
2024-05-31 14:31:27 +00:00
You can get the revision id value, by sending a GET request to get the document details.
You get the document as JSON in the response. For each update to the document, the revision field "_rev" gets changed.
2024-09-17 10:51:49 +00:00
#### Required Parameters:
2024-05-31 14:31:27 +00:00
- **Record ID**
2024-09-17 10:51:49 +00:00
- **Revision ID**
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/updating-v2.png" alt = "Couch update view" / >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
#### Example
2024-05-31 14:31:27 +00:00
```json
2024-09-17 10:51:49 +00:00
[{"name":"tooljet"}]
2024-05-31 14:31:27 +00:00
```
2025-03-21 07:57:24 +00:00
< details id = "tj-dropdown" >
2024-09-17 10:51:49 +00:00
< summary > **Response Example**< / summary >
```json
{
"ok": true,
"id": "23212104e60a71edb42ebc509f0049a2",
"rev": "2-b0a625abc4e21ee554737920156e911f"
}
```
< / details >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
### Delete Record
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
Removes a record from the database by its record ID.
2024-05-31 14:31:27 +00:00
#### Required Parameters:
- **Record ID**
2024-09-17 10:51:49 +00:00
- **Revision ID**
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/deleteRecord.png" alt = "Couch delete view" / >
2024-05-31 14:31:27 +00:00
2025-03-21 07:57:24 +00:00
< details id = "tj-dropdown" >
2024-09-17 10:51:49 +00:00
< summary > **Response Example**< / summary >
```json
{
"ok": true,
"id": "rev_id=2-3d01e0e87139c57e9bd083e48ecde13d& record_id=e33dc4e209689cb0400d095fc401a1e0",
"rev": "1-2b99ef28c03e68ea70bb668ee55ffb7b"
}
```
< / details >
2024-05-31 14:31:27 +00:00
### Find
Find documents using a declarative JSON querying syntax.
#### Required Parameters:
2024-09-17 10:51:49 +00:00
- **Mangoquery**
2024-05-31 14:31:27 +00:00
:::info
NOTE:
selector syntax: https://pouchdb.com/guides/mango-queries.html
:::
2024-09-17 10:51:49 +00:00
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/find-v2.png" alt = "Couch find" / >
2024-05-31 14:31:27 +00:00
2024-09-17 10:51:49 +00:00
#### Example
2024-05-31 14:31:27 +00:00
```json
{
"selector": {
"year": {"$gte": 2015}
},
"fields": ["year"]
}
```
2024-09-17 10:51:49 +00:00
Example response from CouchDB:
2024-05-31 14:31:27 +00:00
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/find_response.png" alt = "Couch find response" / >
2024-09-17 10:51:49 +00:00
### Get View
2024-05-31 14:31:27 +00:00
Views are the primary tool used for querying and reporting on CouchDB documents.
2024-09-17 10:51:49 +00:00
#### Required Parameters
2024-05-31 14:31:27 +00:00
- **View url**
#### Optional Parameters:
- **Start key**
- **End key**
- **Limit**
- **Skip**
2024-09-17 10:51:49 +00:00
< img className = "screenshot-full" src = "/img/datasource-reference/couchdb/get_view-v2.png" alt = "Couch get view" / >
2025-03-21 07:57:24 +00:00
< details id = "tj-dropdown" >
2024-09-17 10:51:49 +00:00
< summary > **Response Example**< / summary >
```json
{
"total_rows": 4,
"offset": 0,
"rows": [
{
"id": "23212104e60a71edb42ebc509f000dc2",
"key": "23212104e60a71edb42ebc509f000dc2",
"value": {
"rev": "1-0cc7f48876f15883394e5c139c628123"
}
},
{
"id": "23212104e60a71edb42ebc509f00216e",
"key": "23212104e60a71edb42ebc509f00216e",
"value": {
"rev": "1-b3c45696b10cb08221a335ff7cbd8b7a"
}
},
{
"id": "23212104e60a71edb42ebc509f00282a",
"key": "23212104e60a71edb42ebc509f00282a",
"value": {
"rev": "1-da5732beb913ecbded309321cac892d2"
}
},
{
"id": "23212104e60a71edb42ebc509f002cbd",
"key": "23212104e60a71edb42ebc509f002cbd",
"value": {
"rev": "1-ca5bb3c0767eb42ea6c33eee3d395b59"
}
2024-05-31 14:31:27 +00:00
}
2024-09-17 10:51:49 +00:00
]
}
```
< / details >
< / div >