Docs

Database API


Server integration with     code examples.

The Database 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 the data in the database service is stored in structured JSON documents. The Appwrite database service also allows you to nest child documents in parent documents and use deep filters to both search and query your data.

Each database document structure in your project is defined using the Appwrite collection rules. The collections rules 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 document in your project for either a specific user, team, user role, or even grant it with public access (*). You can learn more about how Appwrite handles permissions and access control.

Create Collection

POST/v1/database/collections

Create a new Collection.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "collections.write" permission scope.

Request

Name Type Description
name required string

Collection name. Max length: 128 chars.

read required array

An array of strings with read permissions. By default no user is granted with any read permissions. learn more about permissions and get a full list of available permissions.

write required array

An array of strings with write permissions. By default no user is granted with any write permissions. learn more about permissions and get a full list of available permissions.

rules required array

Array of rule objects. Each rule define a collection field name, data type and validation.

Response

Status Code Content Type Payload
201  Created application/json Collection Object
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.createCollection('[NAME]', [], [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.createCollection('[NAME]', [], [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->createCollection('[NAME]', [], [], []);
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.create_collection('[NAME]', [], [], [])
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.create_collection(name: '[NAME]', read: [], write: [], rules: []);
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.CreateCollection("[NAME]", [List<object>], [List<object>], [List<object>]);
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.createCollection(
        name: '[NAME]',
        read: [],
        write: [],
        rules: [],
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database createCollection --name="[NAME]" "--read[]=" "--write[]=" "--rules[]=" 

List Collections

GET/v1/database/collections

Get a list of all the user collections. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project's collections. Learn more about different API modes.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "collections.read" permission scope.

Request

Name Type Description
search optional string

Search term to filter your list results. Max length: 256 chars.

limit optional integer

Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request.

offset optional integer

Results offset. The default value is 0. Use this param to manage pagination.

orderType optional string

Order result by ASC or DESC order.

Response

Status Code Content Type Payload
200  OK application/json Collections List Object
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.listCollections();
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.listCollections();
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->listCollections();
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.list_collections()
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.list_collections();
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.ListCollections();
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.listCollections(
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database listCollections --search="[SEARCH]" --limit="0" --offset="0" --orderType="ASC" 

Get Collection

GET/v1/database/collections/{collectionId}

Get a collection by its unique ID. This endpoint response returns a JSON object with the collection metadata.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "collections.read" permission scope.

Request

Name Type Description
collectionId required string

Collection unique ID.

Response

Status Code Content Type Payload
200  OK application/json Collection Object
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.getCollection('[COLLECTION_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.getCollection('[COLLECTION_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->getCollection('[COLLECTION_ID]');
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.get_collection('[COLLECTION_ID]')
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.get_collection(collection_id: '[COLLECTION_ID]');
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.GetCollection("[COLLECTION_ID]");
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.getCollection(
        collectionId: '[COLLECTION_ID]',
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database getCollection --collectionId="[COLLECTION_ID]" 

Update Collection

PUT/v1/database/collections/{collectionId}

Update a collection by its unique ID.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "collections.write" permission scope.

Request

Name Type Description
collectionId required string

Collection unique ID.

name required string

Collection name. Max length: 128 chars.

read required array

An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions(/docs/permissions) and get a full list of available permissions.

write required array

An array of strings with write permissions. By default no user is granted with any write permissions. learn more about permissions and get a full list of available permissions.

rules optional array

Array of rule objects. Each rule define a collection field name, data type and validation.

Response

Status Code Content Type Payload
200  OK application/json Collection Object
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.updateCollection('[COLLECTION_ID]', '[NAME]', [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.updateCollection('[COLLECTION_ID]', '[NAME]', [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->updateCollection('[COLLECTION_ID]', '[NAME]', [], []);
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.update_collection('[COLLECTION_ID]', '[NAME]', [], [])
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.update_collection(collection_id: '[COLLECTION_ID]', name: '[NAME]', read: [], write: []);
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.UpdateCollection("[COLLECTION_ID]", "[NAME]", [List<object>], [List<object>]);
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.updateCollection(
        collectionId: '[COLLECTION_ID]',
        name: '[NAME]',
        read: [],
        write: [],
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database updateCollection --collectionId="[COLLECTION_ID]" --name="[NAME]" "--read[]=" "--write[]=" "--rules[]=" 

Delete Collection

DELETE/v1/database/collections/{collectionId}

Delete a collection by its unique ID. Only users with write permissions have access to delete this resource.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "collections.write" permission scope.

Request

Name Type Description
collectionId required string

Collection unique ID.

Response

Status Code Content Type Payload
204  No Content - -
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.deleteCollection('[COLLECTION_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.deleteCollection('[COLLECTION_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->deleteCollection('[COLLECTION_ID]');
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.delete_collection('[COLLECTION_ID]')
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.delete_collection(collection_id: '[COLLECTION_ID]');
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.DeleteCollection("[COLLECTION_ID]");
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.deleteCollection(
        collectionId: '[COLLECTION_ID]',
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database deleteCollection --collectionId="[COLLECTION_ID]" 

Create Document

POST/v1/database/collections/{collectionId}/documents

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.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "documents.write" permission scope.

Request

Name Type Description
collectionId required string

Collection unique ID. You can create a new collection with validation rules using the Database service server integration.

data required object

Document data as JSON object.

read required array

An array of strings with read permissions. By default no user is granted with any read permissions. learn more about permissions and get a full list of available permissions.

write required array

An array of strings with write permissions. By default no user is granted with any write permissions. learn more about permissions and get a full list of available permissions.

parentDocument optional string

Parent document unique ID. Use when you want your new document to be a child of a parent document.

parentProperty optional string

Parent document property name. Use when you want your new document to be a child of a parent document.

parentPropertyType optional string

Parent document property connection type. You can set this value to assign, append or prepend, default value is assign. Use when you want your new document to be a child of a parent document.

Response

Status Code Content Type Payload
201  Created application/json JSON Object
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.createDocument('[COLLECTION_ID]', {}, [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.createDocument('[COLLECTION_ID]', {}, [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->createDocument('[COLLECTION_ID]', [], [], []);
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.create_document('[COLLECTION_ID]', {}, [], [])
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.create_document(collection_id: '[COLLECTION_ID]', data: {}, read: [], write: []);
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.CreateDocument("[COLLECTION_ID]", [object], [List<object>], [List<object>]);
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.createDocument(
        collectionId: '[COLLECTION_ID]',
        data: {},
        read: [],
        write: [],
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database createDocument --collectionId="[COLLECTION_ID]" --data="{}" "--read[]=" "--write[]=" --parentDocument="[PARENT_DOCUMENT]" --parentProperty="" --parentPropertyType="assign" 

List Documents

GET/v1/database/collections/{collectionId}/documents

Get a list of all the user documents. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project's documents. Learn more about different API modes.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "documents.read" permission scope.

Request

Name Type Description
collectionId required string

Collection unique ID. You can create a new collection with validation rules using the Database service server integration.

filters optional array

Array of filter strings. Each filter is constructed from a key name, comparison operator (=, !=, >, <, <=, >=) and a value. You can also use a dot (.) separator in attribute names to filter by child document attributes. Examples: 'name=John Doe' or 'category.$id>=5bed2d152c362'.

limit optional integer

Maximum number of documents to return in response. Use this value to manage pagination. By default will return maximum 25 results. Maximum of 100 results allowed per request.

offset optional integer

Offset value. The default value is 0. Use this param to manage pagination.

orderField optional string

Document field that results will be sorted by.

orderType optional string

Order direction. Possible values are DESC for descending order, or ASC for ascending order.

orderCast optional string

Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.

search optional string

Search query. Enter any free text search. The database will try to find a match against all document attributes and children. Max length: 256 chars.

Response

Status Code Content Type Payload
200  OK application/json Documents List Object
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.listDocuments('[COLLECTION_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.listDocuments('[COLLECTION_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->listDocuments('[COLLECTION_ID]');
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.list_documents('[COLLECTION_ID]')
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.list_documents(collection_id: '[COLLECTION_ID]');
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.ListDocuments("[COLLECTION_ID]");
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.listDocuments(
        collectionId: '[COLLECTION_ID]',
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database listDocuments --collectionId="[COLLECTION_ID]" "--filters[]=" --limit="0" --offset="0" --orderField="[ORDER_FIELD]" --orderType="DESC" --orderCast="int" --search="[SEARCH]" 

Get Document

GET/v1/database/collections/{collectionId}/documents/{documentId}

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

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "documents.read" permission scope.

Request

Name Type Description
collectionId required string

Collection unique ID. You can create a new collection with validation rules using the Database service server integration.

documentId required string

Document unique ID.

Response

Status Code Content Type Payload
200  OK application/json JSON Object
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.getDocument('[COLLECTION_ID]', '[DOCUMENT_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.getDocument('[COLLECTION_ID]', '[DOCUMENT_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->getDocument('[COLLECTION_ID]', '[DOCUMENT_ID]');
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.get_document('[COLLECTION_ID]', '[DOCUMENT_ID]')
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.get_document(collection_id: '[COLLECTION_ID]', document_id: '[DOCUMENT_ID]');
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.GetDocument("[COLLECTION_ID]", "[DOCUMENT_ID]");
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.getDocument(
        collectionId: '[COLLECTION_ID]',
        documentId: '[DOCUMENT_ID]',
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database getDocument --collectionId="[COLLECTION_ID]" --documentId="[DOCUMENT_ID]" 

Update Document

PATCH/v1/database/collections/{collectionId}/documents/{documentId}

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

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "documents.write" permission scope.

Request

Name Type Description
collectionId required string

Collection unique ID. You can create a new collection with validation rules using the Database service server integration.

documentId required string

Document unique ID.

data required object

Document data as JSON object.

read required array

An array of strings with read permissions. By default no user is granted with any read permissions. learn more about permissions and get a full list of available permissions.

write required array

An array of strings with write permissions. By default no user is granted with any write permissions. learn more about permissions and get a full list of available permissions.

Response

Status Code Content Type Payload
200  OK application/json JSON Object
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.updateDocument('[COLLECTION_ID]', '[DOCUMENT_ID]', {}, [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.updateDocument('[COLLECTION_ID]', '[DOCUMENT_ID]', {}, [], []);
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->updateDocument('[COLLECTION_ID]', '[DOCUMENT_ID]', [], [], []);
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.update_document('[COLLECTION_ID]', '[DOCUMENT_ID]', {}, [], [])
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.update_document(collection_id: '[COLLECTION_ID]', document_id: '[DOCUMENT_ID]', data: {}, read: [], write: []);
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.UpdateDocument("[COLLECTION_ID]", "[DOCUMENT_ID]", [object], [List<object>], [List<object>]);
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.updateDocument(
        collectionId: '[COLLECTION_ID]',
        documentId: '[DOCUMENT_ID]',
        data: {},
        read: [],
        write: [],
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database updateDocument --collectionId="[COLLECTION_ID]" --documentId="[DOCUMENT_ID]" --data="{}" "--read[]=" "--write[]=" 

Delete Document

DELETE/v1/database/collections/{collectionId}/documents/{documentId}

Delete a document by its unique ID. This endpoint deletes only the parent documents, its attributes and relations to other documents. Child documents will not be deleted.

Authentication

To access this route, init your SDK with your project unique ID and API Key secret token. Make sure your API Key is granted with access to the "documents.write" permission scope.

Request

Name Type Description
collectionId required string

Collection unique ID. You can create a new collection with validation rules using the Database service server integration.

documentId required string

Document unique ID.

Response

Status Code Content Type Payload
204  No Content - -
Example Request
  • const sdk = require('node-appwrite');
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = database.deleteDocument('[COLLECTION_ID]', '[DOCUMENT_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    // Init SDK
    let client = new sdk.Client();
    
    let database = new sdk.Database(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    
    let promise = database.deleteDocument('[COLLECTION_ID]', '[DOCUMENT_ID]');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • <?php
    
    use Appwrite\Client;
    use Appwrite\Services\Database;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $database = new Database($client);
    
    $result = $database->deleteDocument('[COLLECTION_ID]', '[DOCUMENT_ID]');
  • from appwrite.client import Client
    from appwrite.services.database import Database
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    database = Database(client)
    
    result = database.delete_document('[COLLECTION_ID]', '[DOCUMENT_ID]')
    
  • require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    database = Appwrite::Database.new(client);
    
    response = database.delete_document(collection_id: '[COLLECTION_ID]', document_id: '[DOCUMENT_ID]');
    
    puts response
  • using Appwrite;
    
    Client client = new Client();
    
    client
      .SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
      .SetProject("5df5acd0d48c2") // Your project ID
      .SetKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
    ;
    
    Database database = new Database(client);
    
    HttpResponseMessage result = await database.DeleteDocument("[COLLECTION_ID]", "[DOCUMENT_ID]");
    
  • import 'package:dart_appwrite/dart_appwrite.dart';
    
    void main() { // Init SDK
      Client client = Client();
      Database database = Database(client);
    
      client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
      ;
    
      Future result = database.deleteDocument(
        collectionId: '[COLLECTION_ID]',
        documentId: '[DOCUMENT_ID]',
      );
    
      result
        .then((response) {
          print(response);
        }).catchError((error) {
          print(error.response);
      });
    }
  • appwrite database deleteDocument --collectionId="[COLLECTION_ID]" --documentId="[DOCUMENT_ID]"