> 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: wix-data ## Article: Migrate to the SDK ## Article Link: https://dev.wix.com/docs/velo/apis/wix-data/migrate-to-the-sdk.md ## Article Content: # Migrate from `wix-data` to the Data Items SDK As part of Wix's [transition](https://dev.wix.com/docs/velo/articles/api-overview/about-using-the-sdk.md) from Velo to the next-generation JavaScript SDK, you can now use the [Data Items SDK module](https://dev.wix.com/docs/sdk/backend-modules/data/items/introduction.md) for site development. While this module closely mirrors the Velo [`wix-data`](https://dev.wix.com/docs/velo/apis/wix-data/introduction.md) module, there are several functionality changes that might require modifications to your existing site code. Learn more about [migrating from Velo to the SDK](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/develop-with-the-sdk/migrate-from-velo-to-the-sdk.md). Below are important changes to be aware of when migrating to the Data Items SDK module: ## Permission elevation When calling some methods of the Data Items SDK API, you might need to override permission checks. To do that, use [`elevate()`](https://dev.wix.com/docs/sdk/core-modules/essentials/auth.md#elevate). The Data Items SDK API doesn't support the `options.suppressAuth` parameter. Learn more about [permission elevation when developing websites](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-elevated-permissions.md#elevation-when-developing-websites). ## aggregate() The [`aggregate()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/aggregate.md) and [`WixDataAggregate`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate/introduction.md) methods can now return the total number of processed items. When calling the `WixDataAggregate` method [`run()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-aggregate/run.md), set `options.returnTotalCount` to `true` to include the `totalCount` and `totalPages` properties in the aggregation result. For example: ```js import { items } from "@wix/data"; const filter = items.filter().eq("year", 2010); const result = await items .aggregate("PopulationData") .filter(filter) .max("population", "maxPopulation") .descending("maxPopulation") .run({ returnTotalCount: true }); const count = result.totalCount; // 17 const pages = result.totalPages; // 2 ``` ## bulkInsert() The [`bulkInsert()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/bulk-insert.md) method now returns a full `WixDataBulkResult` object. ## bulkRemove() The [`bulkRemove()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/bulk-remove.md) method now returns a full `WixDataBulkResult` object. ## bulkSave() The [`bulkSave()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/bulk-save.md) method now returns a full `WixDataBulkResult` object. ## bulkUpdate() The [`bulkUpdate()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/bulk-update.md) method now returns a full `WixDataBulkResult` object. ## insert() The [`insert()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/insert.md) method no longer modifies the original object passed to it. For example: ```js import { items } from "@wix/data"; const item = { title: "The Adventures of Huckleberry Finn", author: "Mark Twain", }; const insertedItem = await items.insert("books", item); // `insertedItem` contains properties generated by Wix. // `item` remains unchanged. ``` > **Note**: The way Wix Data handles the item in the collection remains unchanged. ## query() The [`query()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/query.md) and [`WixDataQuery`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/introduction.md) methods have been updated with the following changes: ### Total item count Total item count is no longer returned by default. The `WixDataQuery` methods [`distinct()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/distinct.md) and [`find()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/find.md) no longer accept the `options.omitTotalCount` parameter. The query result only includes the `totalCount` and `totalPages` properties if `options.returnTotalCount` is set to `true`. For example: ```js import { items } from "@wix/data"; const result = await items .query("myCollection") .find({ returnTotalCount: true }); const count = result.totalCount; // 17 const pages = result.totalPages; // 2 ``` ### WixDataQuery Changes have been made to the parameters accepted by the following [`WixDataQuery`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/introduction.md) methods: #### and() The [`and()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/and.md) method now accepts a single [`WixDataFilter`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-filter/introduction.md) parameter. #### include() The [`include()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/include.md) method now accepts a query limit parameter. You can limit the number of query results you want to retrieve by specifying a field name and a query limit in the following format: ```js function include(field: string, limit?: number): WixDataQuery; ``` For example: ```js import { items } from "@wix/data"; const results = await items .query("myCollection") .include("referenceField", 10) .find(); ``` #### not() The [`not()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/not.md) method now accepts a single [`WixDataFilter`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-filter/introduction.md) parameter. #### or() The [`or()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-query/or.md) method now accepts a single [`WixDataFilter`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-filter/introduction.md) parameter. ### WixDataResult The query result object [`WixDataResult`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-result/introduction.md) no longer includes the [`query`](https://dev.wix.com/docs/velo/apis/wix-data/wix-data-query-result/query.md) and [`partialIncludes`](https://dev.wix.com/docs/velo/apis/wix-data/wix-data-query-result/partial-includes.md) properties. ## queryReferenced() The [`queryReferenced()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/query-referenced.md) method includes the following changes: ### Total item count Total item count is no longer returned by default. The [`queryReferenced()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/query-referenced.md) method no longer accepts the `options.omitTotalCount` parameter. Instead, the query result only includes the `totalCount` and `totalPages` properties if `options.returnTotalCount` is set to `true`. For example: ```js import { items } from "@wix/data"; const result = await items.queryReferenced("movies", "00001", "actors", { returnTotalCount: true, }); const count = result.totalCount; // 17 const pages = result.totalPages; // 2 ``` ## save() The [`save()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/save.md) method no longer modifies the original object passed to it. For example: ```js import { items } from "@wix/data"; const item = { title: "The Adventures of Huckleberry Finn", author: "Mark Twain", }; const insertedItem = await items.save("books", item); // `insertedItem` contains properties generated by Wix. // `item` remains unchanged. ``` > **Note**: The way Wix Data handles the item in the collection remains unchanged. ## update() The [`update()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/update.md) method no longer modifies the original object passed to it. For example: ```js import { items } from "@wix/data"; const item = { _id: "0001", title: "The Adventures of Huckleberry Finn", author: "Mark Twain", }; const insertedItem = await items.update("books", item); // `insertedItem` contains properties generated by Wix. // `item` remains unchanged. ``` > **Note**: The way Wix Data handles the item in the collection remains unchanged. ## Wix Data errors Wix Data errors include the following changes: ### Errors are standardized Wix Data errors now follow the standardized error format. Learn more about [errors](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-errors.md) in Wix APIs. ### Validation errors specify violating fields [Filter validation error messages](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-errors.md#validation-error-data) now indicate the violating field in the following format: ```console {fieldPath}.{operator} should be a Date, number, or string. Got {value} instead. ``` The following Wix Data errors have the updated format: - WDE0056 - WDE0057 - WDE0058 - WDE0059 - WDE0060 Learn more about [Wix Data error codes](https://dev.wix.com/docs/sdk/backend-modules/data/wix-data-error-codes.md).