Search.../

getDataCollection( )

Developer Preview

Retrieves a data collection by ID.

Syntax

function getDataCollection(dataCollectionId: string, options: GetDataCollectionOptions): Promise<DataCollection>

getDataCollection Parameters

NAME
TYPE
DESCRIPTION
dataCollectionId
string

ID of the collection to retrieve.

options
Optional
GetDataCollectionOptions

Options for retrieving a data collection.

Returns

Details of the collection requested.

Return Type:

Promise<
DataCollection
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date the collection was created.

_id
string

Collection ID. For example, my-first-collection. May include a namespace.

_updatedDate
Date

Date the collection was last updated.

capabilities
CollectionCapabilities

Capabilities the collection supports.

collectionType
string

Collection type. Indicates how the collection was created and is stored.

  • NATIVE: User-created collection.
  • WIX_APP: Collection created by a Wix app, including starter collections created when a Wix app is installed.
  • BLOCKS_APP: Collection created by a Wix Blocks app.
  • EXTERNAL: Collection located in externally connected storage.
defaultDisplayOrder
Sort

Indicates how the collection's items are sorted by default when a query doesn't specify an order.

displayField
string

The field whose value the CMS displays to represent the collection item when referenced in a different collection.

displayName
string

Collection's display name as shown in the CMS. For example, My First Collection.

displayNamespace
string

UI-friendly namespace of the Wix app with which the data collection is associated, such as Stores or Bookings. Empty for all data collections not owned by internal Wix apps.

fields
Array<
Field
>

Collection's field structure.

maxPageSize
number

Maximum number of items returned in a single query, based on the underlying storage. Native collections have a maximum page size of 1000 for offset-based queries or 100 for cursor-based queries. External collections' maximum page size defaults to 50, but an external provider can set any maximum value up to 1000.

ownerAppId
string

ID of the app that defined this collection. For user-defined collections, this value is null.

pagingModes
Array<
string
>

All paging modes the collection supports. In native collections, offset-based paging is supported by default.

permissions
Permissions

Levels of permission for accessing and modifying data, defined by lowest role needed to perform each action.

plugins
Array<
Plugin
>

All plugins the collection uses. Plugins apply additional capabilities to the collection or extend its functionality.

revision
string

Collection's current revision number, which increments each time the collection is updated. For an update operation to succeed, you must pass the latest revision number.

Was this helpful?

Get a collection

Copy Code
1import { collections } from "wix-data.v2";
2
3/* Retrieving a collection with an _id of "myMusicCollection"
4 *
5 * Sample dataCollectionId value:
6 * const dataCollectionId = "myMusicCollection"
7 */
8
9export async function myGetDataCollectionFunction(dataCollectionId) {
10 try {
11 const retrievedCollection = await collections.getDataCollection(dataCollectionId)
12 return retrievedCollection;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17}
18
19/* Returns a promise that resolves to the retrieved collection:
20* {
21* "_id": "myMusicCollection",
22* "collectionType": "NATIVE",
23* "displayName": "My Music Collection",
24* "displayField": "myMusicCollection",
25* "capabilities": {
26* "dataOperations": [
27* "IS_REFERENCED",
28* "INSERT",
29* "SAVE",
30* "BULK_INSERT",
31* "BULK_UPDATE",
32* "UPDATE",
33* "TRUNCATE",
34* "REMOVE",
35* "REMOVE_REFERENCE",
36* "COUNT",
37* "FIND",
38* "REPLACE_REFERENCES",
39* "BULK_REMOVE",
40* "INSERT_REFERENCE",
41* "GET",
42* "BULK_SAVE",
43* "QUERY_REFERENCED",
44* "DISTINCT",
45* "AGGREGATE"
46* ],
47* "collectionOperations": [
48* "UPDATE",
49* "REMOVE"
50* ],
51* "indexLimits": {
52* "regular": 3,
53* "unique": 1,
54* "total": 4
55* }
56* },
57* "fields":
58* [
59* {
60* "key": "artist",
61* "displayName": "Artist Name",
62* "type": "TEXT",
63* "systemField": false,
64* "capabilities": {
65* "sortable": true,
66* "queryOperators": [
67* "EQ",
68* "LT",
69* "GT",
70* "NE",
71* "LTE",
72* "GTE",
73* "STARTS_WITH",
74* "ENDS_WITH",
75* "CONTAINS",
76* "HAS_SOME",
77* "HAS_ALL",
78* "EXISTS",
79* "URLIZED"
80* ]
81* },
82* "encrypted": false,
83* "description": "The artist's name"
84* },
85* {
86* "key": "_id",
87* "displayName": "ID",
88* "type": "TEXT",
89* "systemField": true,
90* "capabilities": {
91* "sortable": true,
92* "queryOperators": [
93* "EQ",
94* "LT",
95* "GT",
96* "NE",
97* "LTE",
98* "GTE",
99* "STARTS_WITH",
100* "ENDS_WITH",
101* "CONTAINS",
102* "HAS_SOME",
103* "HAS_ALL",
104* "EXISTS",
105* "URLIZED"
106* ]
107* },
108* "encrypted": false
109* },
110* {
111* "key": "_createdDate",
112* "displayName": "Created Date",
113* "type": "DATETIME",
114* "systemField": true,
115* "capabilities": {
116* "sortable": true,
117* "queryOperators": [
118* "EQ",
119* "LT",
120* "GT",
121* "NE",
122* "LTE",
123* "GTE",
124* "STARTS_WITH",
125* "ENDS_WITH",
126* "CONTAINS",
127* "HAS_SOME",
128* "HAS_ALL",
129* "EXISTS",
130* "URLIZED"
131* ]
132* },
133* "encrypted": false
134* },
135* {
136* "key": "_updatedDate",
137* "displayName": "Updated Date",
138* "type": "DATETIME",
139* "systemField": true,
140* "capabilities": {
141* "sortable": true,
142* "queryOperators": [
143* "EQ",
144* "LT",
145* "GT",
146* "NE",
147* "LTE",
148* "GTE",
149* "STARTS_WITH",
150* "ENDS_WITH",
151* "CONTAINS",
152* "HAS_SOME",
153* "HAS_ALL",
154* "EXISTS",
155* "URLIZED"
156* ]
157* },
158* "encrypted": false
159* },
160* {
161* "key": "_owner",
162* "displayName": "Owner",
163* "type": "TEXT",
164* "systemField": true,
165* "capabilities": {
166* "sortable": true,
167* "queryOperators": [
168* "EQ",
169* "LT",
170* "GT",
171* "NE",
172* "LTE",
173* "GTE",
174* "STARTS_WITH",
175* "ENDS_WITH",
176* "CONTAINS",
177* "HAS_SOME",
178* "HAS_ALL",
179* "EXISTS",
180* "URLIZED"
181* ]
182* },
183* "encrypted": false
184* }
185* ],
186* "permissions": {
187* "insert": "SITE_MEMBER_AUTHOR",
188* "update": "SITE_MEMBER_AUTHOR",
189* "remove": "SITE_MEMBER_AUTHOR",
190* "read": "ANYONE"
191* },
192* "revision": "1",
193* "plugins": [
194* {
195* "type": "GRIDAPPLESS",
196* "gridapplessOptions": {
197* "migrated": true
198* }
199* }
200* ],
201* "pagingModes": [
202* "OFFSET"
203* ],
204* "_createdDate": "2023-07-19T12:40:02.372Z",
205* "_updatedDate": "2023-07-19T12:40:02.372Z"
206* };
207*/
Get a collection (export from backend code)

Copy Code
1import { Permissions, webMethod } from "wix-web-module";
2import { collections } from "wix-data.v2";
3
4export const myGetDataCollectionFunction = webMethod(Permissions.Anyone, async (dataCollectionId) => {
5 try {
6 const retrievedCollection = await collections.getDataCollection(dataCollectionId);
7 return retrievedCollection;
8 } catch (error) {
9 console.error(error);
10 // Handle the error
11 }
12});
13
14/* Returns a promise that resolves to the retrieved collection:
15* {
16* "_id": "myMusicCollection",
17* "collectionType": "NATIVE",
18* "displayName": "My Music Collection",
19* "displayField": "myMusicCollection",
20* "capabilities": {
21* "dataOperations": [
22* "IS_REFERENCED",
23* "INSERT",
24* "SAVE",
25* "BULK_INSERT",
26* "BULK_UPDATE",
27* "UPDATE",
28* "TRUNCATE",
29* "REMOVE",
30* "REMOVE_REFERENCE",
31* "COUNT",
32* "FIND",
33* "REPLACE_REFERENCES",
34* "BULK_REMOVE",
35* "INSERT_REFERENCE",
36* "GET",
37* "BULK_SAVE",
38* "QUERY_REFERENCED",
39* "DISTINCT",
40* "AGGREGATE"
41* ],
42* "collectionOperations": [
43* "UPDATE",
44* "REMOVE"
45* ],
46* "indexLimits": {
47* "regular": 3,
48* "unique": 1,
49* "total": 4
50* }
51* },
52* "fields":
53* [
54* {
55* "key": "artist",
56* "displayName": "Artist Name",
57* "type": "TEXT",
58* "systemField": false,
59* "capabilities": {
60* "sortable": true,
61* "queryOperators": [
62* "EQ",
63* "LT",
64* "GT",
65* "NE",
66* "LTE",
67* "GTE",
68* "STARTS_WITH",
69* "ENDS_WITH",
70* "CONTAINS",
71* "HAS_SOME",
72* "HAS_ALL",
73* "EXISTS",
74* "URLIZED"
75* ]
76* },
77* "encrypted": false,
78* "description": "The artist's name"
79* },
80* {
81* "key": "_id",
82* "displayName": "ID",
83* "type": "TEXT",
84* "systemField": true,
85* "capabilities": {
86* "sortable": true,
87* "queryOperators": [
88* "EQ",
89* "LT",
90* "GT",
91* "NE",
92* "LTE",
93* "GTE",
94* "STARTS_WITH",
95* "ENDS_WITH",
96* "CONTAINS",
97* "HAS_SOME",
98* "HAS_ALL",
99* "EXISTS",
100* "URLIZED"
101* ]
102* },
103* "encrypted": false
104* },
105* {
106* "key": "_createdDate",
107* "displayName": "Created Date",
108* "type": "DATETIME",
109* "systemField": true,
110* "capabilities": {
111* "sortable": true,
112* "queryOperators": [
113* "EQ",
114* "LT",
115* "GT",
116* "NE",
117* "LTE",
118* "GTE",
119* "STARTS_WITH",
120* "ENDS_WITH",
121* "CONTAINS",
122* "HAS_SOME",
123* "HAS_ALL",
124* "EXISTS",
125* "URLIZED"
126* ]
127* },
128* "encrypted": false
129* },
130* {
131* "key": "_updatedDate",
132* "displayName": "Updated Date",
133* "type": "DATETIME",
134* "systemField": true,
135* "capabilities": {
136* "sortable": true,
137* "queryOperators": [
138* "EQ",
139* "LT",
140* "GT",
141* "NE",
142* "LTE",
143* "GTE",
144* "STARTS_WITH",
145* "ENDS_WITH",
146* "CONTAINS",
147* "HAS_SOME",
148* "HAS_ALL",
149* "EXISTS",
150* "URLIZED"
151* ]
152* },
153* "encrypted": false
154* },
155* {
156* "key": "_owner",
157* "displayName": "Owner",
158* "type": "TEXT",
159* "systemField": true,
160* "capabilities": {
161* "sortable": true,
162* "queryOperators": [
163* "EQ",
164* "LT",
165* "GT",
166* "NE",
167* "LTE",
168* "GTE",
169* "STARTS_WITH",
170* "ENDS_WITH",
171* "CONTAINS",
172* "HAS_SOME",
173* "HAS_ALL",
174* "EXISTS",
175* "URLIZED"
176* ]
177* },
178* "encrypted": false
179* }
180* ],
181* "permissions": {
182* "insert": "SITE_MEMBER_AUTHOR",
183* "update": "SITE_MEMBER_AUTHOR",
184* "remove": "SITE_MEMBER_AUTHOR",
185* "read": "ANYONE"
186* },
187* "revision": "1",
188* "plugins": [
189* {
190* "type": "GRIDAPPLESS",
191* "gridapplessOptions": {
192* "migrated": true
193* }
194* }
195* ],
196* "pagingModes": [
197* "OFFSET"
198* ],
199* "_createdDate": "2023-07-19T12:40:02.372Z",
200* "_updatedDate": "2023-07-19T12:40:02.372Z"
201* };
202*/