Skip to main content
The Records service provides methods for creating, reading, updating, and deleting records in your SnackBase collections.

Overview

Records are the actual data stored in your collections. Each record in a collection has the same structure (schema) defined by the collection’s fields.

List Records

Get all records from a collection with pagination:

With Filtering

With Sorting

With Pagination

With Field Selection

Combined Example

Get a Single Record

Retrieve a specific record by ID:

With Field Selection

Create a Record

Create a new record in a collection:
The id, createdAt, and updatedAt fields are automatically generated by SnackBase.

Update a Record

Full Update (PUT)

Replace all fields of a record:
Using update() replaces all fields. Fields not included will be set to null (unless they have default values).

Partial Update (PATCH)

Update only specific fields:
Use patch() for most updates to avoid accidentally clearing fields.

Delete a Record

Remove a record from a collection:

Using the Query Builder

For complex queries, use the fluent query builder:
See the Query Builder guide for more details.

TypeScript Support

Use TypeScript for type-safe record operations:

Batch Operations

Create Multiple Records

Update Multiple Records

Real-Time Updates

Combine with the real-time service for live updates:

Error Handling

Reference

list(collection, params?)

List records from a collection. Parameters:
  • collection (string) - Collection name
  • params (object) - Query parameters
    • filter (object) - Filter expression
    • sort (string) - Sort expression
    • skip (number) - Records to skip
    • limit (number) - Max records to return
    • fields (string[]) - Fields to return
    • expand (string[]) - Relations to expand
Returns: Promise<RecordListResponse>

get(collection, recordId, params?)

Get a single record by ID. Parameters:
  • collection (string) - Collection name
  • recordId (string) - Record ID
  • params (object) - Query parameters
    • fields (string[]) - Fields to return
    • expand (string[]) - Relations to expand
Returns: Promise<any & BaseRecord>

create(collection, data)

Create a new record. Parameters:
  • collection (string) - Collection name
  • data (object) - Record data
Returns: Promise<any & BaseRecord>

update(collection, recordId, data)

Full update of a record (PUT). Parameters:
  • collection (string) - Collection name
  • recordId (string) - Record ID
  • data (object) - Complete record data
Returns: Promise<any & BaseRecord>

patch(collection, recordId, data)

Partial update of a record (PATCH). Parameters:
  • collection (string) - Collection name
  • recordId (string) - Record ID
  • data (object) - Fields to update
Returns: Promise<any & BaseRecord>

delete(collection, recordId)

Delete a record. Parameters:
  • collection (string) - Collection name
  • recordId (string) - Record ID
Returns: Promise<{ success: boolean }>

query(collection)

Create a query builder for the collection. Parameters:
  • collection (string) - Collection name
Returns: QueryBuilder

Batch Operations

Perform multiple record operations atomically using the dedicated batch endpoint:

Aggregation Queries

Run server-side aggregations without fetching raw records:
Supported functions: count, sum, avg, min, max.

Reference Expansion

Expand reference fields inline to avoid N+1 queries:

Next Steps