Data Structure
Abrova Sync data model — Databases contain Collections, Collections contain Documents, Documents are JSON.
AbrovaSync organizes data into three levels: a Database is the top-level container (created in the Abrova Console), a Collection is a named group of documents inside a database, and a Document is a JSON object with a unique ID.
Apps address databases and collections by name, not by ID: sync.database('my-app').collection('todos'). A database name is unique within a project, and the API key decides which project is used (two projects in one organization may reuse the same name).
Visual model#
Database: my-app
├── Collection: users
│ ├── Document: user_001
│ │ └── { name: "John", email: "john@..." }
│ ├── Document: user_002
│ │ └── { name: "Jane", email: "jane@..." }
│ └── ...
├── Collection: posts
│ ├── Document: post_001
│ │ └── { title: "Hello", content: "..." }
│ └── ...
└── Collection: settings
└── Document: app_config
└── { theme: "dark", version: "1.0" }Identifiers#
| Level | How it is named |
|---|---|
| Database | Created from the Abrova Console. Reference it in code by its name (unique within the project the API key belongs to), not its ID. |
| Collection | Created by its first write from an SDK — a single write or a batch — when your rules allow that write. Letters, digits, - and _, up to 64 characters. Reference it by that name. |
| Document | Auto-generated ID from add() / create(), or a string you pass to set() / update(). |
Creating and managing databases and collections#
As in Firebase, your app's API key only reads and writes documents. Managing the structure belongs to the Console and to your own server:
| Who | What it can do |
|---|---|
| App (API key only) | Read and write documents, which creates a collection on its first write. Listing, creating or deleting databases and collections is refused with 403 server_secret_required. |
| Your server (API key + server secret) | List the databases of its project, and list, read, create and delete collections. Only within the project the API key belongs to. |
| Abrova Console | Everything, including creating, renaming and deleting databases. |
From your server, with the headers x-api-key and x-server-secret:
curl https://sync.abrova.ir/databases \ -H "x-api-key: $ABROVA_API_KEY" -H "x-server-secret: $ABROVA_SERVER_SECRET" curl https://sync.abrova.ir/databases/my-app/collections \ -H "x-api-key: $ABROVA_API_KEY" -H "x-server-secret: $ABROVA_SERVER_SECRET" curl -X DELETE https://sync.abrova.ir/databases/my-app/collections/old-logs \ -H "x-api-key: $ABROVA_API_KEY" -H "x-server-secret: $ABROVA_SERVER_SECRET"
Deleting a collection deletes its documents too, for good. Keep the server secret on your server only — never in an app.
Export and import#
In the Console, Sync › Settings › Data (or a collection's ⋯ menu) exports a database or one collection as a JSON file, and imports a JSON file into a collection: it shows how many documents are new or would replace one with the same id, then merges by id or replaces the whole collection. Imports follow the same path as writes from the Console, so apps listening to the collection see every change, and they are not billed as reads or writes.