---
updatedAt: 2025-07-15T08:51:22.000Z
agentTools:
  projectIndex: https://docs.appery.io/llms.txt
---

# Collection

Server Code API to work with the database.

Collection API integration with the [Appery.io](https://appery.io) **[Database](https://appery.io/database/)**. With this API you can access the database, search the database, create, update, and delete objects.

> 👍 Using Server Code to Access the Database
>
> We recommend to access the database from the [Appery.io](https://appery.io) **[Server Code](https://appery.io/servercode/)** instead of accessing the database directly from the app. This approach has the following benefits:
>
> * Sort the database results.
> * Filter the database results.
> * Query the database two or more times.
> * Run any custom logic before, or after querying the database.

If server code script is linked with database on Settings tab

<Image align="center" src="https://files.readme.io/f65cef9c25f07f4b54c7e17c7bd17f857ed6f2ddad2532b55b69d7aaa2299c2f-img-2025-01-21-18-26-35.png" />

Then, the `databaseId` and `masterKey` can be obtained using the following code:

```javascript
var dbId = Apperyio.env.apiKeys[0];
var masterKey = Apperyio.env.masterKey;

```

<br />

# Method Summary

**Collection** has the following methods:

| Method                                                                                         | Description                                                                             |
| :--------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------- |
| getCollectionList(dbApiKey)                                                                    | Returns a list of a collection info of a specific database.                             |
| createObject(dbApiKey, collectionName, objectJSON\[, token])                                   | Creates an object in the specified collection.                                          |
| retrieveObject(dbApiKey, collectionName, objectId, include\[, token])                          | Retrieves an object from the specified collection.                                      |
| updateObject(dbApiKey, collectionName, objectId, objectJSON\[, token])                         | Updates object into the specified collection.                                           |
| multiUpdateObject(dbApiKey, collectionName, queryString, updateJSON, operationsJSON\[, token]) | Updates multiple objects by specified values.                                           |
| deleteObject(dbApiKey, collectionName, objectId\[, token])                                     | Deletes object from the specified collection.                                           |
| multiDeleteObject(dbApiKey, collectionName, queryString\[, token])                             | Deletes multiple objects from the specified collection that matches specified criteria. |
| query(dbApiKey, collectionName\[, token])                                                      | Queries a list of objects from a specified collection.                                  |
| distinct(dbApiKey, collectionName, columnName\[, token])                                       | Queries a list of distinct values from a specified collection’s column.                 |