Collections_
Organize your data with Appwrite Collections. Explore how to create and configure collections to store and structure your data effectively.
3 min read
Appwrite uses collections as containers of documents. Each collection contains many documents identical in structure. The terms collections and documents are used because the Appwrite JSON REST API resembles the API of a traditional NoSQL database, making it intuitive and user-friendly, even though Appwrite uses SQL under the hood.
That said, Appwrite is designed to support both SQL and NoSQL database adapters like MariaDB, MySQL, or MongoDB in future versions.
Create collection
You can create collections using the Appwrite Console, a Server SDK, or using the CLI.
Permissions
Appwrite uses permissions to control data access. For security, only users that are granted permissions can access a resource. This helps prevent accidental data leaks by forcing you to make more concious decisions around permissions.
By default, Appwrite doesn't grant permissions to any users when a new collection is created. This means users can't create new documents or read, update, and delete existing documents.
Learn about configuring permissions.
Attributes
All documents in a collection follow the same structure. Attributes are used to define the structure of your documents and help the Appwrite's API validate your users' input. Add your first attribute by clicking the Add attribute button.
You can choose between the following types.
| Attribute | Description |
|---|---|
string | String attribute. |
integer | Integer attribute. |
float | Float attribute. |
boolean | Boolean attribute. |
datetime | Datetime attribute formatted as an ISO 8601 string. |
enum | Enum attribute. |
ip | IP address attribute for IPv4 and IPv6. |
email | Email address attribute. |
url | URL attribute. |
relationship | Relationship attribute relates one collection to another. Learn more about relationships. |
If an attribute must be populated in all documents, set it as required. If not, you may optionally set a default value. Additionally, decide if the attribute should be a single value or an array of values.
If needed, you can change an attribute's key, default value, size (for strings), and whether it is required or not after creation.
You can increase a string attribute's size without any restrictions. When decreasing size, you must ensure that your existing data is less than or equal to the new size, or the operation will fail.
Indexes
Databases use indexes to quickly locate data without having to search through every document for matches. To ensure the best performance, Appwrite recommends an index for every attribute queried. If you plan to query multiple attributes in a single query, creating an index with all queried attributes will yield optimal performance.
The following indexes are currently supported:
| Type | Description |
|---|---|
key | Plain Index to allow queries. |
unique | Unique Index to disallow duplicates. |
fulltext | For searching within string attributes. Required for the search query method. |
You can create an index by navigating to your collection's Indexes tab or by using your favorite Server SDK.
Was this page helpful?
Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.