Databases

CLIENT

The Databases service allows you to create structured collections 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://cloud.appwrite.io/v1

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.

  • Response
Endpoint
GET /databases/{databaseId}/collections/{collectionId}/documents
Android (Java)
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import io.appwrite.Client
import io.appwrite.services.Databases

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Client client = new Client(getApplicationContext())
            .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
            .setProject("5df5acd0d48c2"); // Your project ID

        Databases databases = new Databases(client);

        databases.listDocuments(
            "[DATABASE_ID]", 
            "[COLLECTION_ID]", 
            new Continuation<Object>() {
                @NotNull
                @Override
                public CoroutineContext getContext() {
                    return EmptyCoroutineContext.INSTANCE;
                }

                @Override
                public void resumeWith(@NotNull Object o) {
                    String json = "";
                    try {
                        if (o instanceof Result.Failure) {
                            Result.Failure failure = (Result.Failure) o;
                            throw failure.exception;
                        } else {
                            Response response = (Response) o;
                            json = response.body().string();
                        }                    
                    } catch (Throwable th) {
                        Log.e("ERROR", th.toString());
                    }
                }
            }
        );
    }
}

Create Document

Create a new Document. Before using this route, you should create a new collection resource using either a server integration API or directly from your database console.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration. Make sure to define attributes before creating documents.

    • documentId string
      required

      Document ID. Choose your own unique ID or pass the string ID.unique() to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

    • data object
      required

      Document data as JSON object.

    • permissions array

      An array of permissions strings. By default the current user is granted with all permissions. Learn more about permissions.

  • 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 minutes 120 requests IP + METHOD + URL + USER ID
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/documents
Android (Java)
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import io.appwrite.Client
import io.appwrite.services.Databases

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Client client = new Client(getApplicationContext())
            .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
            .setProject("5df5acd0d48c2"); // Your project ID

        Databases databases = new Databases(client);

        databases.createDocument(
            "[DATABASE_ID]", 
            "[COLLECTION_ID]", 
            "[DOCUMENT_ID]", 
            mapOf( "a" to "b" ), 
            new Continuation<Object>() {
                @NotNull
                @Override
                public CoroutineContext getContext() {
                    return EmptyCoroutineContext.INSTANCE;
                }

                @Override
                public void resumeWith(@NotNull Object o) {
                    String json = "";
                    try {
                        if (o instanceof Result.Failure) {
                            Result.Failure failure = (Result.Failure) o;
                            throw failure.exception;
                        } else {
                            Response response = (Response) o;
                            json = response.body().string();
                        }                    
                    } catch (Throwable th) {
                        Log.e("ERROR", th.toString());
                    }
                }
            }
        );
    }
}

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.

  • Response
Endpoint
GET /databases/{databaseId}/collections/{collectionId}/documents/{documentId}
Android (Java)
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import io.appwrite.Client
import io.appwrite.services.Databases

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Client client = new Client(getApplicationContext())
            .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
            .setProject("5df5acd0d48c2"); // Your project ID

        Databases databases = new Databases(client);

        databases.getDocument(
            "[DATABASE_ID]", 
            "[COLLECTION_ID]", 
            "[DOCUMENT_ID]"
            new Continuation<Object>() {
                @NotNull
                @Override
                public CoroutineContext getContext() {
                    return EmptyCoroutineContext.INSTANCE;
                }

                @Override
                public void resumeWith(@NotNull Object o) {
                    String json = "";
                    try {
                        if (o instanceof Result.Failure) {
                            Result.Failure failure = (Result.Failure) o;
                            throw failure.exception;
                        } else {
                            Response response = (Response) o;
                            json = response.body().string();
                        }                    
                    } catch (Throwable th) {
                        Log.e("ERROR", th.toString());
                    }
                }
            }
        );
    }
}

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.

  • 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 minutes 120 requests IP + METHOD + URL + USER ID
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/documents/{documentId}
Android (Java)
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import io.appwrite.Client
import io.appwrite.services.Databases

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Client client = new Client(getApplicationContext())
            .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
            .setProject("5df5acd0d48c2"); // Your project ID

        Databases databases = new Databases(client);

        databases.updateDocument(
            "[DATABASE_ID]", 
            "[COLLECTION_ID]", 
            "[DOCUMENT_ID]", 
            new Continuation<Object>() {
                @NotNull
                @Override
                public CoroutineContext getContext() {
                    return EmptyCoroutineContext.INSTANCE;
                }

                @Override
                public void resumeWith(@NotNull Object o) {
                    String json = "";
                    try {
                        if (o instanceof Result.Failure) {
                            Result.Failure failure = (Result.Failure) o;
                            throw failure.exception;
                        } else {
                            Response response = (Response) o;
                            json = response.body().string();
                        }                    
                    } catch (Throwable th) {
                        Log.e("ERROR", th.toString());
                    }
                }
            }
        );
    }
}

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.

  • Response
    • 204 application/json
  • 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 minutes 60 requests IP + METHOD + URL + USER ID
Endpoint
DELETE /databases/{databaseId}/collections/{collectionId}/documents/{documentId}
Android (Java)
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import io.appwrite.Client
import io.appwrite.services.Databases

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Client client = new Client(getApplicationContext())
            .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
            .setProject("5df5acd0d48c2"); // Your project ID

        Databases databases = new Databases(client);

        databases.deleteDocument(
            "[DATABASE_ID]", 
            "[COLLECTION_ID]", 
            "[DOCUMENT_ID]"
            new Continuation<Object>() {
                @NotNull
                @Override
                public CoroutineContext getContext() {
                    return EmptyCoroutineContext.INSTANCE;
                }

                @Override
                public void resumeWith(@NotNull Object o) {
                    String json = "";
                    try {
                        if (o instanceof Result.Failure) {
                            Result.Failure failure = (Result.Failure) o;
                            throw failure.exception;
                        } else {
                            Response response = (Response) o;
                            json = response.body().string();
                        }                    
                    } catch (Throwable th) {
                        Log.e("ERROR", th.toString());
                    }
                }
            }
        );
    }
}