Search.../

updateDataCollection( )

Updates a data collection.

Description

A collection ID, revision number, permissions, and at least 1 field must be provided within options.collection. If a collection with that ID exists, and if its current revision number matches the one provided, it is updated. Otherwise, the request fails.

When a collection is updated, its _updatedDate property is changed to the current date and its revision property is incremented.

Note: After a collection is updated, it only contains the properties included in the updateDataCollection() call. If the existing collection has properties with values and those properties aren't included in the updated collection details, their values are lost.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function updateDataCollection(collection: DataCollection): Promise<DataCollection>

updateDataCollection Parameters

NAME
TYPE
DESCRIPTION
collection
DataCollection

Updated collection details. The existing collection is replaced with this version.

Returns

Updated collection details.

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?

Updates an existing collection (dashboard page code)

Copy Code
1
2import { collections } from "wix-data.v2";
3
4/* Example collection parameter:
5 * Elevate read permissions to SITE_MEMBER, and add a field
6 *
7 * const updatedDataCollection = {
8 * _id: "myMusicCollection",
9 * fields:
10 * [
11 * {
12 * key: "artist",
13 * displayName: "Artist Name",
14 * description: "The artist's name",
15 * },
16 * {
17 * key: "song",
18 * displayName: "Song Title",
19 * description: "The song's title",
20 * "required": true
21 * },
22 * ]
23 * revision: "1",
24 * permissions: {
25 * read: "SITE_MEMBER",
26 * insert: "SITE_MEMBER_AUTHOR",
27 * update: "SITE_MEMBER_AUTHOR",
28 * remove: "SITE_MEMBER_AUTHOR"
29 * },
30 * };
31 */
32
33
34export async function myUpdateDataCollectionFunction(updatedDataCollection) {
35 try {
36 const updateDataCollectionResponse = await collections.updateDataCollection(updatedDataCollection);
37 return updateDataCollectionResponse;
38 } catch (error) {
39 console.error(error);
40 // Handle the error
41 }
42}
43
44/* Returns a promise that resolves to the updated collection:
45 * {
46 * "_id": "myMusicCollection",
47 * "collectionType": "NATIVE",
48 * "displayName": "My Music Collection",
49 * "displayField": "myMusicCollection",
50 * "capabilities": {
51 * "dataOperations": [
52 * "IS_REFERENCED",
53 * "INSERT",
54 * "SAVE",
55 * "BULK_INSERT",
56 * "BULK_UPDATE",
57 * "UPDATE",
58 * "TRUNCATE",
59 * "REMOVE",
60 * "REMOVE_REFERENCE",
61 * "COUNT",
62 * "FIND",
63 * "REPLACE_REFERENCES",
64 * "BULK_REMOVE",
65 * "INSERT_REFERENCE",
66 * "GET",
67 * "BULK_SAVE",
68 * "QUERY_REFERENCED",
69 * "DISTINCT",
70 * "AGGREGATE"
71 * ],
72 * "collectionOperations": [
73 * "UPDATE",
74 * "REMOVE"
75 * ],
76 * "indexLimits": {
77 * "regular": 3,
78 * "unique": 1,
79 * "total": 4
80 * }
81 * },
82 * "fields": [
83 * {
84 * "key": "artist",
85 * "displayName": "Artist Name",
86 * "type": "TEXT",
87 * "systemField": false,
88 * "capabilities": {
89 * "sortable": true,
90 * "queryOperators": [
91 * "EQ",
92 * "LT",
93 * "GT",
94 * "NE",
95 * "LTE",
96 * "GTE",
97 * "STARTS_WITH",
98 * "ENDS_WITH",
99 * "CONTAINS",
100 * "HAS_SOME",
101 * "HAS_ALL",
102 * "EXISTS",
103 * "URLIZED"
104 * ]
105 * },
106 * "encrypted": false,
107 * "description": "The artist's name",
108 * "required": true
109 * },
110 * {
111 * "key": "song",
112 * "displayName": "Song Title",
113 * "type": "TEXT",
114 * "systemField": false,
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 * "description": "The song's title",
135 * "required": true
136 * },
137 * {
138 * "key": "_id",
139 * "displayName": "ID",
140 * "type": "TEXT",
141 * "systemField": true,
142 * "capabilities": {
143 * "sortable": true,
144 * "queryOperators": [
145 * "EQ",
146 * "LT",
147 * "GT",
148 * "NE",
149 * "LTE",
150 * "GTE",
151 * "STARTS_WITH",
152 * "ENDS_WITH",
153 * "CONTAINS",
154 * "HAS_SOME",
155 * "HAS_ALL",
156 * "EXISTS",
157 * "URLIZED"
158 * ]
159 * },
160 * "encrypted": false
161 * },
162 * {
163 * "key": "_createdDate",
164 * "displayName": "Created Date",
165 * "type": "DATETIME",
166 * "systemField": true,
167 * "capabilities": {
168 * "sortable": true,
169 * "queryOperators": [
170 * "EQ",
171 * "LT",
172 * "GT",
173 * "NE",
174 * "LTE",
175 * "GTE",
176 * "STARTS_WITH",
177 * "ENDS_WITH",
178 * "CONTAINS",
179 * "HAS_SOME",
180 * "HAS_ALL",
181 * "EXISTS",
182 * "URLIZED"
183 * ]
184 * },
185 * "encrypted": false
186 * },
187 * {
188 * "key": "_updatedDate",
189 * "displayName": "Updated Date",
190 * "type": "DATETIME",
191 * "systemField": true,
192 * "capabilities": {
193 * "sortable": true,
194 * "queryOperators": [
195 * "EQ",
196 * "LT",
197 * "GT",
198 * "NE",
199 * "LTE",
200 * "GTE",
201 * "STARTS_WITH",
202 * "ENDS_WITH",
203 * "CONTAINS",
204 * "HAS_SOME",
205 * "HAS_ALL",
206 * "EXISTS",
207 * "URLIZED"
208 * ]
209 * },
210 * "encrypted": false
211 * },
212 * {
213 * "key": "_owner",
214 * "displayName": "Owner",
215 * "type": "TEXT",
216 * "systemField": true,
217 * "capabilities": {
218 * "sortable": true,
219 * "queryOperators": [
220 * "EQ",
221 * "LT",
222 * "GT",
223 * "NE",
224 * "LTE",
225 * "GTE",
226 * "STARTS_WITH",
227 * "ENDS_WITH",
228 * "CONTAINS",
229 * "HAS_SOME",
230 * "HAS_ALL",
231 * "EXISTS",
232 * "URLIZED"
233 * ]
234 * },
235 * "encrypted": false
236 * }
237 * ],
238 * "permissions": {
239 * "insert": "SITE_MEMBER",
240 * "update": "SITE_MEMBER_AUTHOR",
241 * "remove": "SITE_MEMBER_AUTHOR",
242 * "read": "SITE_MEMBER_AUTHOR"
243 * },
244 * "revision": "2",
245 * "plugins": [
246 * {
247 * "type": "GRIDAPPLESS",
248 * "gridapplessOptions": {
249 * "migrated": true
250 * }
251 * }
252 * ],
253 * "pagingModes": [
254 * "OFFSET"
255 * ],
256 * "_createdDate": "2023-07-19T12:40:02.372Z",
257 * "_updatedDate": "2023-07-19T14:00:28.836Z"
258 * }
259 */
Updates an existing collection (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { collections } from 'wix-data.v2';
3
4export const myUpdateDataCollectionFunction = webMethod(Permissions.Anyone, async (updatedDataCollection) => {
5 try {
6 const updateDataCollectionResponse = await collections.updateDataCollection(updatedDataCollection);
7 return updateDataCollectionResponse;
8 } catch (error) {
9 console.error(error);
10 // Handle the error
11 }
12});
13
14/* Returns a promise that resolves to the updated 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 * "key": "artist",
55 * "displayName": "Artist Name",
56 * "type": "TEXT",
57 * "systemField": false,
58 * "capabilities": {
59 * "sortable": true,
60 * "queryOperators": [
61 * "EQ",
62 * "LT",
63 * "GT",
64 * "NE",
65 * "LTE",
66 * "GTE",
67 * "STARTS_WITH",
68 * "ENDS_WITH",
69 * "CONTAINS",
70 * "HAS_SOME",
71 * "HAS_ALL",
72 * "EXISTS",
73 * "URLIZED"
74 * ]
75 * },
76 * "encrypted": false,
77 * "description": "The artist's name",
78 * "required": true
79 * },
80 * {
81 * "key": "song",
82 * "displayName": "Song Title",
83 * "type": "TEXT",
84 * "systemField": false,
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 * "description": "The song's title",
105 * "required": true
106 * },
107 * {
108 * "key": "_id",
109 * "displayName": "ID",
110 * "type": "TEXT",
111 * "systemField": true,
112 * "capabilities": {
113 * "sortable": true,
114 * "queryOperators": [
115 * "EQ",
116 * "LT",
117 * "GT",
118 * "NE",
119 * "LTE",
120 * "GTE",
121 * "STARTS_WITH",
122 * "ENDS_WITH",
123 * "CONTAINS",
124 * "HAS_SOME",
125 * "HAS_ALL",
126 * "EXISTS",
127 * "URLIZED"
128 * ]
129 * },
130 * "encrypted": false
131 * },
132 * {
133 * "key": "_createdDate",
134 * "displayName": "Created Date",
135 * "type": "DATETIME",
136 * "systemField": true,
137 * "capabilities": {
138 * "sortable": true,
139 * "queryOperators": [
140 * "EQ",
141 * "LT",
142 * "GT",
143 * "NE",
144 * "LTE",
145 * "GTE",
146 * "STARTS_WITH",
147 * "ENDS_WITH",
148 * "CONTAINS",
149 * "HAS_SOME",
150 * "HAS_ALL",
151 * "EXISTS",
152 * "URLIZED"
153 * ]
154 * },
155 * "encrypted": false
156 * },
157 * {
158 * "key": "_updatedDate",
159 * "displayName": "Updated Date",
160 * "type": "DATETIME",
161 * "systemField": true,
162 * "capabilities": {
163 * "sortable": true,
164 * "queryOperators": [
165 * "EQ",
166 * "LT",
167 * "GT",
168 * "NE",
169 * "LTE",
170 * "GTE",
171 * "STARTS_WITH",
172 * "ENDS_WITH",
173 * "CONTAINS",
174 * "HAS_SOME",
175 * "HAS_ALL",
176 * "EXISTS",
177 * "URLIZED"
178 * ]
179 * },
180 * "encrypted": false
181 * },
182 * {
183 * "key": "_owner",
184 * "displayName": "Owner",
185 * "type": "TEXT",
186 * "systemField": true,
187 * "capabilities": {
188 * "sortable": true,
189 * "queryOperators": [
190 * "EQ",
191 * "LT",
192 * "GT",
193 * "NE",
194 * "LTE",
195 * "GTE",
196 * "STARTS_WITH",
197 * "ENDS_WITH",
198 * "CONTAINS",
199 * "HAS_SOME",
200 * "HAS_ALL",
201 * "EXISTS",
202 * "URLIZED"
203 * ]
204 * },
205 * "encrypted": false
206 * }
207 * ],
208 * "permissions": {
209 * "insert": "SITE_MEMBER",
210 * "update": "SITE_MEMBER_AUTHOR",
211 * "remove": "SITE_MEMBER_AUTHOR",
212 * "read": "SITE_MEMBER_AUTHOR"
213 * },
214 * "revision": "2",
215 * "plugins": [
216 * {
217 * "type": "GRIDAPPLESS",
218 * "gridapplessOptions": {
219 * "migrated": true
220 * }
221 * }
222 * ],
223 * "pagingModes": [
224 * "OFFSET"
225 * ],
226 * "_createdDate": "2023-07-19T12:40:02.372Z",
227 * "_updatedDate": "2023-07-19T14:00:28.836Z"
228 * }
229 */
230
Updates an existing collection

This function effectively replaces the existing collection with the collection passed as a parameter.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { collections } from 'wix-data.v2';
3
4export const myUpdateDataCollectionFunction = webMethod(Permissions.Anyone, async (updatedCollection) => {
5 try {
6 const updateDataCollectionResponse = await collections.updateDataCollection(updatedCollection);
7 return updateDataCollectionResponse;
8 } catch (error) {
9 console.error(error);
10 // Handle the error
11 }
12});
13
14/* Returns a promise that resolves to the updated collection:
15 * {
16 * "_id": "shirts",
17 * "collectionType": "NATIVE",
18 * "displayName": "Shirts",
19 * "displayField": "shirts",
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 * "key": "name",
55 * "displayName": "Item Name",
56 * "type": "TEXT",
57 * "systemField": false,
58 * "capabilities": {
59 * "sortable": true,
60 * "queryOperators": [
61 * "EQ",
62 * "LT",
63 * "GT",
64 * "NE",
65 * "LTE",
66 * "GTE",
67 * "STARTS_WITH",
68 * "ENDS_WITH",
69 * "CONTAINS",
70 * "HAS_SOME",
71 * "HAS_ALL",
72 * "EXISTS",
73 * "URLIZED"
74 * ]
75 * },
76 * "encrypted": false,
77 * "description": "Name of item, required",
78 * "required": true
79 * },
80 * {
81 * "key": "price",
82 * "displayName": "Price of Item",
83 * "type": "NUMBER",
84 * "systemField": false,
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 * "description": "Price of item, required",
105 * "required": true
106 * },
107 * {
108 * "key": "desc",
109 * "displayName": "Item Description",
110 * "type": "TEXT",
111 * "systemField": false,
112 * "capabilities": {
113 * "sortable": true,
114 * "queryOperators": [
115 * "EQ",
116 * "LT",
117 * "GT",
118 * "NE",
119 * "LTE",
120 * "GTE",
121 * "STARTS_WITH",
122 * "ENDS_WITH",
123 * "CONTAINS",
124 * "HAS_SOME",
125 * "HAS_ALL",
126 * "EXISTS",
127 * "URLIZED"
128 * ]
129 * },
130 * "encrypted": false,
131 * "description": "Item description, not required"
132 * },
133 * {
134 * "key": "_id",
135 * "displayName": "ID",
136 * "type": "TEXT",
137 * "systemField": true,
138 * "capabilities": {
139 * "sortable": true,
140 * "queryOperators": [
141 * "EQ",
142 * "LT",
143 * "GT",
144 * "NE",
145 * "LTE",
146 * "GTE",
147 * "STARTS_WITH",
148 * "ENDS_WITH",
149 * "CONTAINS",
150 * "HAS_SOME",
151 * "HAS_ALL",
152 * "EXISTS",
153 * "URLIZED"
154 * ]
155 * },
156 * "encrypted": false
157 * },
158 * {
159 * "key": "_createdDate",
160 * "displayName": "Created Date",
161 * "type": "DATETIME",
162 * "systemField": true,
163 * "capabilities": {
164 * "sortable": true,
165 * "queryOperators": [
166 * "EQ",
167 * "LT",
168 * "GT",
169 * "NE",
170 * "LTE",
171 * "GTE",
172 * "STARTS_WITH",
173 * "ENDS_WITH",
174 * "CONTAINS",
175 * "HAS_SOME",
176 * "HAS_ALL",
177 * "EXISTS",
178 * "URLIZED"
179 * ]
180 * },
181 * "encrypted": false
182 * },
183 * {
184 * "key": "_updatedDate",
185 * "displayName": "Updated Date",
186 * "type": "DATETIME",
187 * "systemField": true,
188 * "capabilities": {
189 * "sortable": true,
190 * "EXISTS",
191 * "URLIZED"
192 * ]
193 * },
194 * "encrypted": false
195 * },
196 * {
197 * "key": "_draftDate",
198 * "displayName": "Unpublish Date",
199 * "type": "DATETIME",
200 * "systemField": true,
201 * "capabilities": {
202 * "sortable": true,
203 * "queryOperators": [
204 * "EQ",
205 * "LT",
206 * "GT",
207 * "NE",
208 * "LTE",
209 * "GTE",
210 * "STARTS_WITH",
211 * "ENDS_WITH",
212 * "CONTAINS",
213 * "HAS_SOME",
214 * "HAS_ALL",
215 * "EXISTS",
216 * "URLIZED"
217 * ]
218 * },
219 * "encrypted": false
220 * }
221 * ],
222 * "permissions": {
223 * "insert": "SITE_MEMBER_AUTHOR",
224 * "update": "SITE_MEMBER_AUTHOR",
225 * "remove": "SITE_MEMBER_AUTHOR",
226 * "read": "ANYONE"
227 * },
228 * "revision": "2",
229 * "plugins": [
230 * {
231 * "type": "URLIZED",
232 * "urlizedOptions": {
233 * "format": "ORIGINAL"
234 * }
235 * },
236 * {
237 * "type": "PUBLISH",
238 * "publishOptions": {
239 * "defaultStatus": "DRAFT"
240 * }
241 * },
242 * {
243 * "type": "GRIDAPPLESS",
244 * "gridapplessOptions": {
245 * "migrated": true
246 * }
247 * }
248 * ],
249 * "pagingModes": [
250 * "OFFSET"
251 * ],
252 * "_createdDate": "2023-07-23T11:38:41.518Z",
253 * "_updatedDate": "2023-07-23T13:13:49.154Z"
254 * };
255 */
256