Skip to main content

Custom Collection

The sdk.customCollection utility enables you to interact with GridStudio's custom NoSQL-style collections directly within Server SDK functions. You can list, read, create, update, and delete documents across tenant- or app-scoped collections using a consistent API.


API

await sdk.customCollection(name, { scope, slug })

Returns a handler object with async methods to perform CRUD operations on the custom collection.

⚠️ This function itself is asynchronous, so you must await the collection handler before calling its methods.

MethodDescription
listAsync(options)Lists documents using query options.
showAsync(_id)Retrieves a single document by ID.
createAsync(payload)Inserts a new document.
updateAsync(_id, payload)Updates a document by ID.
updateManyAsync(query, payload)Updates multiple documents matching query.
deleteAsync(_id)Deletes a document by ID.
findOneAsync(query, options)Finds a single document by query.

Parameters

  • name (string): Name of the custom collection to access.
  • scope ("app" | "tenant" | "global"): Optional. Defaults to "app".
  • slug (string): Optional. Target tenant slug. Defaults to current tenant.

Example

const Properties = await sdk.customCollection('properties')

const { datas: properties, options } = await Properties.listAsync({
filtering: { status: 'active' },
pagination: { currentPage: 1, pageItems: 10 },
})

sdk.utils.logger.info('Fetched properties:', properties)

Notes

  • For scope: 'app', the function automatically includes the current customAppInstanceId.
  • Accessing another tenant’s data requires it to be a child of the current tenant, and authorization is verified.
  • All operations are asynchronous.
  • Remember to await the initial sdk.customCollection(...) call before using any of its methods.