Skip to content

Databases

CLIENT

The Databases service allows you to create structured collection of documents, query and filter lists of documents, and manage an advanced set of read and write access permissions.

All data returned by the Databases service are represented as structured JSON documents.

The Databases service can contain multiple databases, each database can contain multiple collections. A collection is a group of similarly structured documents. The accepted structure of documents is defined by collection attributes. The collection attributes help you ensure all your user-submitted data is validated and stored according to the collection structure.

Using Appwrite permissions architecture, you can assign read or write access to each collection or document in your project for either a specific user, team, user role, or even grant it with public access (any). You can learn more about how Appwrite handles permissions and access control.

Base URL
https://<REGION>.cloud.appwrite.io/v1

Get document

Get a document by its unique ID. This endpoint response returns a JSON object with the document data.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • documentId string
      required

      Document ID.

    • queries array

      Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long.

    • transactionId string

      Transaction ID to read uncommitted changes within the transaction.

  • Response
Endpoint
GET /databases/{databaseId}/collections/{collectionId}/documents/{documentId}
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

Document result = await databases.getDocument(
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    documentId: '<DOCUMENT_ID>',
    queries: [], // optional
    transactionId: '<TRANSACTION_ID>', // optional
);

List documents

Get a list of all the user's documents in a given collection. You can use the query params to filter your results.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • queries array

      Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long.

    • transactionId string

      Transaction ID to read uncommitted changes within the transaction.

  • Response
Endpoint
GET /databases/{databaseId}/collections/{collectionId}/documents
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

DocumentList result = await databases.listDocuments(
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    queries: [], // optional
    transactionId: '<TRANSACTION_ID>', // optional
);

Update document

Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID.

    • documentId string
      required

      Document ID.

    • data object

      Document data as JSON object. Include only attribute and value pairs to be updated.

    • transactionId string

      Transaction ID for staging the operation.

  • Response
  • Rate limits

    This endpoint is rate limited. You can only make a limited number of request to his endpoint within a specific time frame.

    The limit is applied for each unique limit key.

    Time frame
    Attempts
    Key
    1 minutes120 requestsIP + METHOD + URL + USER ID
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/documents/{documentId}
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

Document result = await databases.updateDocument(
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    documentId: '<DOCUMENT_ID>',
    data: {}, // optional
    permissions: ["read("any")"], // optional
    transactionId: '<TRANSACTION_ID>', // optional
);

Delete document

Delete a document by its unique ID.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • documentId string
      required

      Document ID.

    • transactionId string

      Transaction ID for staging the operation.

  • Response
    • 204 no content
  • Rate limits

    This endpoint is rate limited. You can only make a limited number of request to his endpoint within a specific time frame.

    The limit is applied for each unique limit key.

    Time frame
    Attempts
    Key
    1 minutes60 requestsIP + METHOD + URL + USER ID
Endpoint
DELETE /databases/{databaseId}/collections/{collectionId}/documents/{documentId}
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

await databases.deleteDocument(
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    documentId: '<DOCUMENT_ID>',
    transactionId: '<TRANSACTION_ID>', // optional
);

Increment document attribute

Increment a specific attribute of a document by a given value.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID.

    • documentId string
      required

      Document ID.

    • attribute string
      required

      Attribute key.

    • value number

      Value to increment the attribute by. The value must be a number.

    • max number

      Maximum value for the attribute. If the current value is greater than this value, an error will be thrown.

    • transactionId string

      Transaction ID for staging the operation.

  • Response
  • Rate limits

    This endpoint is rate limited. You can only make a limited number of request to his endpoint within a specific time frame.

    The limit is applied for each unique limit key.

    Time frame
    Attempts
    Key
    1 minutes120 requestsIP + METHOD + URL + USER ID
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

Document result = await databases.incrementDocumentAttribute(
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    documentId: '<DOCUMENT_ID>',
    attribute: '',
    value: 0, // optional
    max: 0, // optional
    transactionId: '<TRANSACTION_ID>', // optional
);

Decrement document attribute

Decrement a specific attribute of a document by a given value.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID.

    • documentId string
      required

      Document ID.

    • attribute string
      required

      Attribute key.

    • value number

      Value to increment the attribute by. The value must be a number.

    • min number

      Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown.

    • transactionId string

      Transaction ID for staging the operation.

  • Response
  • Rate limits

    This endpoint is rate limited. You can only make a limited number of request to his endpoint within a specific time frame.

    The limit is applied for each unique limit key.

    Time frame
    Attempts
    Key
    1 minutes120 requestsIP + METHOD + URL + USER ID
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

Document result = await databases.decrementDocumentAttribute(
    databaseId: '<DATABASE_ID>',
    collectionId: '<COLLECTION_ID>',
    documentId: '<DOCUMENT_ID>',
    attribute: '',
    value: 0, // optional
    min: 0, // optional
    transactionId: '<TRANSACTION_ID>', // optional
);

Create operations

Create multiple operations in a single transaction.

  • Request
    • transactionId string
      required

      Transaction ID.

    • operations array

      Array of staged operations.

  • Response
Endpoint
POST /databases/transactions/{transactionId}/operations
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

Transaction result = await databases.createOperations(
    transactionId: '<TRANSACTION_ID>',
    operations: [
	    {
	        "action": "create",
	        "databaseId": "<DATABASE_ID>",
	        "collectionId": "<COLLECTION_ID>",
	        "documentId": "<DOCUMENT_ID>",
	        "data": {
	            "name": "Walter O'Brien"
	        }
	    }
	], // optional
);

Create transaction

Create a new transaction.

  • Request
    • ttl integer

      Seconds before the transaction expires.

  • Response
Endpoint
POST /databases/transactions
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

Transaction result = await databases.createTransaction(
    ttl: 60, // optional
);

Get transaction

Get a transaction by its unique ID.

  • Request
    • transactionId string
      required

      Transaction ID.

  • Response
Endpoint
GET /databases/transactions/{transactionId}
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

Transaction result = await databases.getTransaction(
    transactionId: '<TRANSACTION_ID>',
);

List transactions

List transactions across all databases.

Endpoint
GET /databases/transactions
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

TransactionList result = await databases.listTransactions(
    queries: [], // optional
);

Update transaction

Update a transaction, to either commit or roll back its operations.

  • Request
    • transactionId string
      required

      Transaction ID.

    • commit boolean

      Commit transaction?

    • rollback boolean

      Rollback transaction?

  • Response
Endpoint
PATCH /databases/transactions/{transactionId}
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

Transaction result = await databases.updateTransaction(
    transactionId: '<TRANSACTION_ID>',
    commit: false, // optional
    rollback: false, // optional
);

Delete transaction

Delete a transaction by its unique ID.

  • Request
    • transactionId string
      required

      Transaction ID.

  • Response
    • 204 no content
Endpoint
DELETE /databases/transactions/{transactionId}
Flutter
import 'package:appwrite/appwrite.dart';

Client client = Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>'); // Your project ID

Databases databases = Databases(client);

await databases.deleteTransaction(
    transactionId: '<TRANSACTION_ID>',
);