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.
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
Updated collection details. The existing collection is replaced with this version.
Returns
Updated collection details.
Return Type:
NAME
TYPE
DESCRIPTION
Date the collection was created.
Collection ID. For example, my-first-collection
. May include a namespace.
Date the collection was last updated.
Capabilities the collection supports.
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.
Indicates how the collection's items are sorted by default when a query doesn't specify an order.
The field whose value the CMS displays to represent the collection item when referenced in a different collection.
Collection's display name as shown in the CMS. For example, My First Collection
.
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.
Collection's field structure.
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.
ID of the app that defined this collection. For user-defined collections, this value is null.
All paging modes the collection supports. In native collections, offset-based paging is supported by default.
Levels of permission for accessing and modifying data, defined by lowest role needed to perform each action.
All plugins the collection uses. Plugins apply additional capabilities to the collection or extend its functionality.
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?
12import { collections } from "wix-data.v2";34/* Example collection parameter:5 * Elevate read permissions to SITE_MEMBER, and add a field6 *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": true21 * },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 */323334export 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 error41 }42}4344/* 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": 480 * }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": true109 * },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": true136 * },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": false161 * },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": false186 * },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": false211 * },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": false236 * }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": true250 * }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 */
1import { Permissions, webMethod } from 'wix-web-module';2import { collections } from 'wix-data.v2';34/* Example collection parameter:5 * Elevate read permissions to SITE_MEMBER, and add a field6 *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": true21 * },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 */3233export const myUpdateDataCollectionFunction = webMethod(Permissions.Anyone, async (updatedDataCollection) => {34 try {35 const updateDataCollectionResponse = await collections.updateDataCollection(updatedDataCollection);36 return updateDataCollectionResponse;37 } catch (error) {38 console.error(error);39 // Handle the error40 }41});4243/* Returns a promise that resolves to the updated collection:44 * {45 * "_id": "myMusicCollection",46 * "collectionType": "NATIVE",47 * "displayName": "My Music Collection",48 * "displayField": "myMusicCollection",49 * "capabilities": {50 * "dataOperations": [51 * "IS_REFERENCED",52 * "INSERT",53 * "SAVE",54 * "BULK_INSERT",55 * "BULK_UPDATE",56 * "UPDATE",57 * "TRUNCATE",58 * "REMOVE",59 * "REMOVE_REFERENCE",60 * "COUNT",61 * "FIND",62 * "REPLACE_REFERENCES",63 * "BULK_REMOVE",64 * "INSERT_REFERENCE",65 * "GET",66 * "BULK_SAVE",67 * "QUERY_REFERENCED",68 * "DISTINCT",69 * "AGGREGATE"70 * ],71 * "collectionOperations": [72 * "UPDATE",73 * "REMOVE"74 * ],75 * "indexLimits": {76 * "regular": 3,77 * "unique": 1,78 * "total": 479 * }80 * },81 * "fields": [82 * {83 * "key": "artist",84 * "displayName": "Artist Name",85 * "type": "TEXT",86 * "systemField": false,87 * "capabilities": {88 * "sortable": true,89 * "queryOperators": [90 * "EQ",91 * "LT",92 * "GT",93 * "NE",94 * "LTE",95 * "GTE",96 * "STARTS_WITH",97 * "ENDS_WITH",98 * "CONTAINS",99 * "HAS_SOME",100 * "HAS_ALL",101 * "EXISTS",102 * "URLIZED"103 * ]104 * },105 * "encrypted": false,106 * "description": "The artist's name",107 * "required": true108 * },109 * {110 * "key": "song",111 * "displayName": "Song Title",112 * "type": "TEXT",113 * "systemField": false,114 * "capabilities": {115 * "sortable": true,116 * "queryOperators": [117 * "EQ",118 * "LT",119 * "GT",120 * "NE",121 * "LTE",122 * "GTE",123 * "STARTS_WITH",124 * "ENDS_WITH",125 * "CONTAINS",126 * "HAS_SOME",127 * "HAS_ALL",128 * "EXISTS",129 * "URLIZED"130 * ]131 * },132 * "encrypted": false,133 * "description": "The song's title",134 * "required": true135 * },136 * {137 * "key": "_id",138 * "displayName": "ID",139 * "type": "TEXT",140 * "systemField": true,141 * "capabilities": {142 * "sortable": true,143 * "queryOperators": [144 * "EQ",145 * "LT",146 * "GT",147 * "NE",148 * "LTE",149 * "GTE",150 * "STARTS_WITH",151 * "ENDS_WITH",152 * "CONTAINS",153 * "HAS_SOME",154 * "HAS_ALL",155 * "EXISTS",156 * "URLIZED"157 * ]158 * },159 * "encrypted": false160 * },161 * {162 * "key": "_createdDate",163 * "displayName": "Created Date",164 * "type": "DATETIME",165 * "systemField": true,166 * "capabilities": {167 * "sortable": true,168 * "queryOperators": [169 * "EQ",170 * "LT",171 * "GT",172 * "NE",173 * "LTE",174 * "GTE",175 * "STARTS_WITH",176 * "ENDS_WITH",177 * "CONTAINS",178 * "HAS_SOME",179 * "HAS_ALL",180 * "EXISTS",181 * "URLIZED"182 * ]183 * },184 * "encrypted": false185 * },186 * {187 * "key": "_updatedDate",188 * "displayName": "Updated Date",189 * "type": "DATETIME",190 * "systemField": true,191 * "capabilities": {192 * "sortable": true,193 * "queryOperators": [194 * "EQ",195 * "LT",196 * "GT",197 * "NE",198 * "LTE",199 * "GTE",200 * "STARTS_WITH",201 * "ENDS_WITH",202 * "CONTAINS",203 * "HAS_SOME",204 * "HAS_ALL",205 * "EXISTS",206 * "URLIZED"207 * ]208 * },209 * "encrypted": false210 * },211 * {212 * "key": "_owner",213 * "displayName": "Owner",214 * "type": "TEXT",215 * "systemField": true,216 * "capabilities": {217 * "sortable": true,218 * "queryOperators": [219 * "EQ",220 * "LT",221 * "GT",222 * "NE",223 * "LTE",224 * "GTE",225 * "STARTS_WITH",226 * "ENDS_WITH",227 * "CONTAINS",228 * "HAS_SOME",229 * "HAS_ALL",230 * "EXISTS",231 * "URLIZED"232 * ]233 * },234 * "encrypted": false235 * }236 * ],237 * "permissions": {238 * "insert": "SITE_MEMBER",239 * "update": "SITE_MEMBER_AUTHOR",240 * "remove": "SITE_MEMBER_AUTHOR",241 * "read": "SITE_MEMBER_AUTHOR"242 * },243 * "revision": "2",244 * "plugins": [245 * {246 * "type": "GRIDAPPLESS",247 * "gridapplessOptions": {248 * "migrated": true249 * }250 * }251 * ],252 * "pagingModes": [253 * "OFFSET"254 * ],255 * "_createdDate": "2023-07-19T12:40:02.372Z",256 * "_updatedDate": "2023-07-19T14:00:28.836Z"257 * }258 */259
This function effectively replaces the existing collection with the collection passed as a parameter.
1import { Permissions, webMethod } from 'wix-web-module';2import { collections } from 'wix-data.v2';34/* Example collection object:5 *6 * Existing fields are added a "type" property. In addition, a plugin has been added that defines each new * item in the collection draft by default. You can publish them at a later date.7 *8 * const updatedCollection = {9 * _id: "shirts",10 * revision: "1",11 * displayName: "Shirts",12 * displayField: "shirts",13 * permissions: {14 * read: "ANYONE",15 * insert: "SITE_MEMBER_AUTHOR",16 * update: "SITE_MEMBER_AUTHOR",17 * remove: "SITE_MEMBER_AUTHOR"18 * },19 * fields:20 * [21 * {22 * key: "name",23 * displayName: "Item Name",24 * description: "Name of item, required",25 * required: true,26 * type: "TEXT"27 * },28 * {29 * key: "price",30 * displayName: "Price of Item",31 * description: "Price of item, required",32 * required: true,33 * type: "NUMBER"34 * },35 * {36 * key: "desc",37 * displayName: "Item Description",38 * description: "Item description, not required",39 * type: "TEXT"40 * },41 * ],42 * plugins:43 * [44 * {45 * type: "URLIZED",46 * urlizedOptions: {47 * format: "ORIGINAL"48 * }49 * },50 * {51 * type: "PUBLISH",52 * publishOptions: {53 * defaultStatus: "DRAFT"54 * }55 * }56 * ]57 * };58 */5960export const myUpdateDataCollectionFunction = webMethod(Permissions.Anyone, async (updatedCollection) => {61 try {62 const updateDataCollectionResponse = await collections.updateDataCollection(updatedCollection);63 return updateDataCollectionResponse;64 } catch (error) {65 console.error(error);66 // Handle the error67 }68});6970/* Returns a promise that resolves to the updated collection:71 * {72 * "_id": "shirts",73 * "collectionType": "NATIVE",74 * "displayName": "Shirts",75 * "displayField": "shirts",76 * "capabilities": {77 * "dataOperations": [78 * "IS_REFERENCED",79 * "INSERT",80 * "SAVE",81 * "BULK_INSERT",82 * "BULK_UPDATE",83 * "UPDATE",84 * "TRUNCATE",85 * "REMOVE",86 * "REMOVE_REFERENCE",87 * "COUNT",88 * "FIND",89 * "REPLACE_REFERENCES",90 * "BULK_REMOVE",91 * "INSERT_REFERENCE",92 * "GET",93 * "BULK_SAVE",94 * "QUERY_REFERENCED",95 * "DISTINCT",96 * "AGGREGATE"97 * ],98 * "collectionOperations": [99 * "UPDATE",100 * "REMOVE"101 * ],102 * "indexLimits": {103 * "regular": 3,104 * "unique": 1,105 * "total": 4106 * }107 * },108 * "fields": [109 * {110 * "key": "name",111 * "displayName": "Item Name",112 * "type": "TEXT",113 * "systemField": false,114 * "capabilities": {115 * "sortable": true,116 * "queryOperators": [117 * "EQ",118 * "LT",119 * "GT",120 * "NE",121 * "LTE",122 * "GTE",123 * "STARTS_WITH",124 * "ENDS_WITH",125 * "CONTAINS",126 * "HAS_SOME",127 * "HAS_ALL",128 * "EXISTS",129 * "URLIZED"130 * ]131 * },132 * "encrypted": false,133 * "description": "Name of item, required",134 * "required": true135 * },136 * {137 * "key": "price",138 * "displayName": "Price of Item",139 * "type": "NUMBER",140 * "systemField": false,141 * "capabilities": {142 * "sortable": true,143 * "queryOperators": [144 * "EQ",145 * "LT",146 * "GT",147 * "NE",148 * "LTE",149 * "GTE",150 * "STARTS_WITH",151 * "ENDS_WITH",152 * "CONTAINS",153 * "HAS_SOME",154 * "HAS_ALL",155 * "EXISTS",156 * "URLIZED"157 * ]158 * },159 * "encrypted": false,160 * "description": "Price of item, required",161 * "required": true162 * },163 * {164 * "key": "desc",165 * "displayName": "Item Description",166 * "type": "TEXT",167 * "systemField": false,168 * "capabilities": {169 * "sortable": true,170 * "queryOperators": [171 * "EQ",172 * "LT",173 * "GT",174 * "NE",175 * "LTE",176 * "GTE",177 * "STARTS_WITH",178 * "ENDS_WITH",179 * "CONTAINS",180 * "HAS_SOME",181 * "HAS_ALL",182 * "EXISTS",183 * "URLIZED"184 * ]185 * },186 * "encrypted": false,187 * "description": "Item description, not required"188 * },189 * {190 * "key": "_id",191 * "displayName": "ID",192 * "type": "TEXT",193 * "systemField": true,194 * "capabilities": {195 * "sortable": true,196 * "queryOperators": [197 * "EQ",198 * "LT",199 * "GT",200 * "NE",201 * "LTE",202 * "GTE",203 * "STARTS_WITH",204 * "ENDS_WITH",205 * "CONTAINS",206 * "HAS_SOME",207 * "HAS_ALL",208 * "EXISTS",209 * "URLIZED"210 * ]211 * },212 * "encrypted": false213 * },214 * {215 * "key": "_createdDate",216 * "displayName": "Created Date",217 * "type": "DATETIME",218 * "systemField": true,219 * "capabilities": {220 * "sortable": true,221 * "queryOperators": [222 * "EQ",223 * "LT",224 * "GT",225 * "NE",226 * "LTE",227 * "GTE",228 * "STARTS_WITH",229 * "ENDS_WITH",230 * "CONTAINS",231 * "HAS_SOME",232 * "HAS_ALL",233 * "EXISTS",234 * "URLIZED"235 * ]236 * },237 * "encrypted": false238 * },239 * {240 * "key": "_updatedDate",241 * "displayName": "Updated Date",242 * "type": "DATETIME",243 * "systemField": true,244 * "capabilities": {245 * "sortable": true,246 * "EXISTS",247 * "URLIZED"248 * ]249 * },250 * "encrypted": false251 * },252 * {253 * "key": "_draftDate",254 * "displayName": "Unpublish Date",255 * "type": "DATETIME",256 * "systemField": true,257 * "capabilities": {258 * "sortable": true,259 * "queryOperators": [260 * "EQ",261 * "LT",262 * "GT",263 * "NE",264 * "LTE",265 * "GTE",266 * "STARTS_WITH",267 * "ENDS_WITH",268 * "CONTAINS",269 * "HAS_SOME",270 * "HAS_ALL",271 * "EXISTS",272 * "URLIZED"273 * ]274 * },275 * "encrypted": false276 * }277 * ],278 * "permissions": {279 * "insert": "SITE_MEMBER_AUTHOR",280 * "update": "SITE_MEMBER_AUTHOR",281 * "remove": "SITE_MEMBER_AUTHOR",282 * "read": "ANYONE"283 * },284 * "revision": "2",285 * "plugins": [286 * {287 * "type": "URLIZED",288 * "urlizedOptions": {289 * "format": "ORIGINAL"290 * }291 * },292 * {293 * "type": "PUBLISH",294 * "publishOptions": {295 * "defaultStatus": "DRAFT"296 * }297 * },298 * {299 * "type": "GRIDAPPLESS",300 * "gridapplessOptions": {301 * "migrated": true302 * }303 * }304 * ],305 * "pagingModes": [306 * "OFFSET"307 * ],308 * "_createdDate": "2023-07-23T11:38:41.518Z",309 * "_updatedDate": "2023-07-23T13:13:49.154Z"310 * };311 */312