A valid request URL is required to generate request examples{
"transactionId": 100,
"queryType": "select",
"items": [
{
"_id": 1,
"name": "Francis",
"favoriteBook": {
"title": "The Great Gatsby",
"published": 1925
}
}
],
"mutatedDocumentIds": [],
"error": {},
"warnings": [],
"totalWarningsCount": 0
}Execute a DQL query
Execute a Ditto Query Language (DQL) statement against your data store. DQL is a powerful query language that supports complex queries, updates, and data manipulation. This endpoint serves as the primary interface for running DQL operations. See the comprehensive DQL guide for detailed syntax and examples.
A valid request URL is required to generate request examples{
"transactionId": 100,
"queryType": "select",
"items": [
{
"_id": 1,
"name": "Francis",
"favoriteBook": {
"title": "The Great Gatsby",
"published": 1925
}
}
],
"mutatedDocumentIds": [],
"error": {},
"warnings": [],
"totalWarningsCount": 0
}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.
Authorization
All requests to this endpoint require authentication using an API key or JWT token in theAuthorization: Bearer header. For detailed instructions on creating and managing API keys, see Auth and Parameters.
API versions
This endpoint is available at both/api/v4/store/execute and /api/v5/store/execute. The v5 API defaults to DQL_STRICT_MODE=false, which treats nested objects as MAPs instead of REGISTERs. For more information, see API v4 vs v5.
Examples
The following examples demonstrate common DQL operations using curl. Replace{YOUR_CLOUD_URL_ENDPOINT} with your Cloud URL Endpoint from the portal (see Getting your Cloud URL Endpoint) and {YOUR_API_KEY} with your API key.
Insert a document
Insert a new document into a collection:curl -X POST 'https://{YOUR_CLOUD_URL_ENDPOINT}/api/v5/store/execute' \
-H 'Authorization: Bearer {YOUR_API_KEY}' \
-H 'Content-Type: application/json' \
-d '{
"statement": "INSERT INTO cars DOCUMENTS (:newCar)",
"args": {
"newCar": {
"_id": "car-123",
"make": "Toyota",
"model": "Camry",
"year": 2024,
"color": "blue"
}
}
}'
Select documents
Query documents from a collection:curl -X POST 'https://{YOUR_CLOUD_URL_ENDPOINT}/api/v5/store/execute' \
-H 'Authorization: Bearer {YOUR_API_KEY}' \
-H 'Content-Type: application/json' \
-d '{
"statement": "SELECT * FROM cars WHERE color = :color",
"args": {
"color": "blue"
}
}'
Update a document
Update an existing document:curl -X POST 'https://{YOUR_CLOUD_URL_ENDPOINT}/api/v5/store/execute' \
-H 'Authorization: Bearer {YOUR_API_KEY}' \
-H 'Content-Type: application/json' \
-d '{
"statement": "UPDATE cars SET color = :newColor WHERE _id = :id",
"args": {
"newColor": "red",
"id": "car-123"
}
}'
Delete a document
DELETE operation permanently removes documents from the Ditto system. Deleted documents cannot be recovered. For detailed guidance on delete behavior, tombstones, and best practices, see Removing Documents.Key considerations:- Deleting large numbers of documents (50,000+) at once can impact system performance. Use
LIMITto batch deletions. - Concurrent delete and update operations on the same document can result in unexpected “husked documents.”
- Consider using the soft-delete pattern or
EVICTfor local-only removal instead of permanent deletion.
curl -X POST 'https://{YOUR_CLOUD_URL_ENDPOINT}/api/v5/store/execute' \
-H 'Authorization: Bearer {YOUR_API_KEY}' \
-H 'Content-Type: application/json' \
-d '{
"statement": "DELETE FROM cars WHERE _id = :id",
"args": {
"id": "car-123"
}
}'
curl -X POST 'https://{YOUR_CLOUD_URL_ENDPOINT}/api/v5/store/execute' \
-H 'Authorization: Bearer {YOUR_API_KEY}' \
-H 'Content-Type: application/json' \
-d '{
"statement": "DELETE FROM cars WHERE year < :year LIMIT 30000",
"args": {
"year": 2020
}
}'
Upsert a document
Insert a document or update it if it already exists:curl -X POST 'https://{YOUR_CLOUD_URL_ENDPOINT}/api/v5/store/execute' \
-H 'Authorization: Bearer {YOUR_API_KEY}' \
-H 'Content-Type: application/json' \
-d '{
"statement": "INSERT INTO cars DOCUMENTS (:car) ON ID CONFLICT DO UPDATE",
"args": {
"car": {
"_id": "car-123",
"make": "Toyota",
"model": "Camry",
"year": 2024,
"color": "green",
"mileage": 15000
}
}
}'
Response
A successful response includes:transactionId: The transaction ID for this operationqueryType: The type of query executed (e.g., “select”, “insert”, “update”, “delete”)items: For SELECT queries, the array of matching documentsmutatedDocumentIds: For mutations, the IDs of affected documents
API reference
Authorizations
Authentication using either an API key or JWT token in the Authorization header
Headers
Optional transaction ID that ensures consistency across operations. When provided, the operation will only execute if the Big Peer's current transaction ID meets or exceeds this value, preventing stale reads and ensuring causal consistency in your application.
Body
The DQL statement to execute, along with any parameterized arguments. Using parameterized queries with the args field helps prevent injection attacks and improves query performance through statement caching.
Request parameters for executing a DQL statement. DQL is Ditto's powerful query language that supports complex queries and data modifications.
The DQL statement to execute. See https://docs.ditto.live/dql-guide for comprehensive documentation on DQL syntax and features.
Named parameters to use in the DQL statement, providing safe value substitution and better query performance
Response
The DQL statement executed successfully. The response includes the results of the query, any mutated document IDs, the transaction ID, and any warnings that occurred during execution. For SELECT queries, results appear in the items array. For mutations, affected IDs appear in mutatedDocumentIds.
Response from executing a DQL statement. Contains query results, affected document IDs, and any warnings or errors that occurred.
Indicates the type of query that was executed
Total number of warnings generated during query execution
Show child attributes
Show child attributes
An error occurred that prevented the query from executing or completing successfully
Show child attributes
Show child attributes
Was this page helpful?