> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt ## Resource: Data Collections Extension Files and Code ## Article: Data Collections Extension Files and Code ## Article Link: https://dev.wix.com/docs/wix-cli/guides/extensions/backend-extensions/data-collections/data-collections-extension-files-and-code.md ## Article Content: # Data Collections Extension Files and Code
This feature is in Developer Preview and is subject to change.
When you generate a [data collections extension](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/data-collections/about-data-collections-extensions.md), the CLI adds the following files to your project: ```bash src/ └── extensions/ └── backend/ └── data-collections/ ├── data-collections.extension.ts # Shared extension file └── .ts # Collection definition file ``` - `data-collections.extension.ts`: Builds the [data collections extension](#data-collections-builder-file). - `.ts`: Defines the [collection's schema, permissions, indexes, and initial data](#data-collection-definition-file). Each file represents a collection. The CLI also adds an import and a `.use()` call to your project's [`extensions.ts`](https://dev.wix.com/docs/wix-cli/guides/extensions/about-the-extensions-ts-file.md) file so the extension is registered with your project. > **Note**: You can move these files to any location in the `src/` folder and update the references in your `extensions.ts` file. Learn more about the [flexible file system](https://dev.wix.com/docs/wix-cli/guides/get-started/project-structure.md#your-custom-extension-folder). ## Data collections builder file The `data-collections.extension.ts` file contains the data collections extension's builder configuration. The builder is defined using the following schema: ```ts import { extensions } from '@wix/astro/builders'; export default extensions.dataCollections({ id: string, name: string, collections: Collection[], }); ``` Here's an example builder definition with 2 registered collections: ```ts import { extensions } from "@wix/astro/builders"; import customerFeedbackCollection from "./customer-feedback"; import productReviewsCollection from "./product-reviews"; export default extensions.dataCollections({ id: "c7bdcb61-9c98-45d5-8a1e-76ce89b407eb", name: "Data Collections", collections: [customerFeedbackCollection, productReviewsCollection], }); ``` ### Data collection builder fields The following fields can be used in the builder's configuration object: | Field | Type | Description | | ------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | string | Required. The data collections extension ID as a [GUID](https://en.wikipedia.org/wiki/Universally_unique_identifier). Wix automatically generates it when you add the extension. It must be unique across all extensions in the project. | | `name` | string | Required. A human-readable name for the extension. Defaults to `'Data Collections'`. You can edit it directly in the file, and view it in the app dashboard under **Extensions**. | | `collections` | array | Required. The default exports from each `.ts` collection definition file you want this extension to register. Each time you generate a new collection, the CLI adds it to this array. | ## Data collection definition file Each `.ts` file defines a single collection. The default export is an object that follows the schema documented in the [data collections extension JSON reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections-extension/introduction.md). Each collection definition file comes with default fields, default permissions, and other configuration that you can customize. The starting file looks like this: ```ts export const collectionIdSuffix = ""; export default { idSuffix: collectionIdSuffix, displayName: "", fields: [ { type: "TEXT", displayName: "Title", key: "title" }, { type: "IMAGE", displayName: "Image", key: "image" }, ], displayField: "title", dataPermissions: { itemInsert: "CMS_EDITOR", itemRead: "CMS_EDITOR", itemRemove: "CMS_EDITOR", itemUpdate: "CMS_EDITOR", }, indexes: [], initialData: [], }; ``` The file also exports a named constant, `collectionIdSuffix`, which has the same string used as `idSuffix`. To reference this collection elsewhere in your project, import this constant from your backend code. ### Collection fields The default export object accepts the following top-level fields. For the full schema, including supported field types, permission roles, index options, and the initial-data format, see the [data collections extension JSON reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections-extension/introduction.md). | Field | Type | Description | | ----------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `idSuffix` | string | Required. The suffix appended to the full collection ID. The full ID in the CMS becomes `@//`. It must be 1-36 characters and can only contain letters, numbers, underscores, and hyphens. | | `displayName` | string | Required. The collection's display name in the CMS. | | `displayField` | string | Required. The `key` of the field used to identify items in this collection when they're referenced from other collections. | | `fields` | array | Required. The collection's schema. See the [supported field types](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections-extension/introduction.md). | | `dataPermissions` | object | Required. The role required for each [item action](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-permissions/introduction.md#item-actions): `itemInsert`, `itemRead`, `itemRemove`, and `itemUpdate`. | | `indexes` | array | Indexes to improve query performance. | | `initialData` | array | Items to seed the collection with when it's first created on a site. Each item must conform to the schema declared in `fields`. | ## See also - [Add a Data Collections Extension with the Wix CLI](https://dev.wix.com/docs/wix-cli/guides/extensions/backend-extensions/data-collections/add-a-data-collections-extension-with-the-wix-cli.md) - [About Data Collections Extensions](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/data-collections/about-data-collections-extensions.md) - [Data Collections Extension JSON Reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections-extension/introduction.md) - [About the Wix Data Collections API](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections/introduction.md)