Skip to main content
Runtime modules are the built-in capabilities you call from automations on the foundation, and the collections module is one of them. It provides structured data storage and querying for automations, supporting both MongoDB and SQL backends, with automatic namespace isolation per workspace and app.
This module is meant to be used through the Collection application, which provides a ready-to-use UI for managing collections and schemas. The functions below are available directly via the run instruction for advanced use cases.

Schema Management

All collections automatically include createdAt, updatedAt, createdBy, and updatedBy fields.
Returns an array of collection names in the current workspace/app namespace.
Returns all schema definitions for the current namespace.
Returns usage statistics (document count, size, etc.).
Analyzes data and returns an inferred schema with warnings. Provide either collection or data.
Lists the collections whose database table differs from their schema: the configuration of their Collection instance, or the last schema applied for a collection no instance declares (declaredIn). Reads only, and only the tables of the caller’s workspace (or app).
PostgreSQL only: on MongoDB, drift is always false.
Runs the given migrations, then those of the collection’s configuration and the automatic ones, then synchronizes the collection with its schema, like an update of its configuration: in one transaction, with the same workspaces.collections.migrated and workspaces.collections.notMigrated events. Returns applied, failed, skipped (columns left alone, with howTo convert them) and rolledBack. If the synchronization fails, the conversions are rolled back and the error details list them.With dryRun: true, nothing is converted and the table is not locked against reads: planned lists what would run (cast, rows, retyped). The schema is validated as the real run would, but the synchronization that follows the conversions is not tried: one that fails on the data (a unique constraint on duplicate rows…) only shows up in the real run, which then rolls the conversions back.Only conversions to jsonb of properties the schema declares json can be passed in migrations. The synchronization that follows brings every column back to its declared type: any other conversion would be undone at once, after rewriting the data twice. Declare the property json first. Such a migration, or an invalid one (unknown op, cast or to), is refused before anything runs.
  • Every call without dryRun synchronizes the collection and makes every runtime reload it, even when there is nothing to convert. Call it once to fix a drift, never on a schedule or on each page load.
  • Do not pass migrations from a request ({{body.migrations}} behind an endpoint): until now only an editor of the workspace could declare a migration, in the configuration. Whoever calls the endpoint could rewrite a column of the collection.
  • In an app, the collection’s table is shared by every workspace the app is installed in. The schema is read from the app version the calling workspace installed, and the conversion applies to every workspace.
PostgreSQL only: on MongoDB, the result is empty.

Read Operations

Returns [entities, totalCount], useful for paginated UIs.

Write Operations

createdAt and updatedAt are set automatically.

Update Operations

updatedAt is set automatically. Returns { modifiedCount, matchedCount }.
An empty query without allowMatchAll: true throws an error to prevent accidental mass updates.
Same parameters and behavior as updateOne, but affects all matching documents.
createdAt is set only on insert; updatedAt is always set.

Delete Operations

Returns { deletedCount }.
An empty query without allowMatchAll: true throws an error to prevent accidental mass deletion.
Same parameters as deleteOne, but deletes all matching documents.

Query Syntax

Queries use MongoDB-style operators:

Complete Example