Collection
API reference for the Collection class
Constructor
Internal — collections are created by Database.collection().
Properties
collection.name: string
Methods
create()
create(data: Partial<T>): Promise<Model<T> & T>
Creates a record. Applies defaults, validates schema, runs plugin hooks.
get()
get(id: ID): Promise<(Model<T> & T) | undefined>
Fetches a record by ID. Returns undefined if not found.
getAll()
getAll(): Promise<(Model<T> & T)[]>
Returns every record in the collection.
update()
update(id: ID, changes: Partial<T>): Promise<Model<T> & T>
Merges changes into an existing record. Throws if record not found.
delete()
delete(id: ID): Promise<void>
Deletes a record by ID. Returns normally even if the record does not exist.
deleteMany()
deleteMany(ids: ID[]): Promise<void>
Deletes multiple records. Silently skips missing IDs.
await notes.deleteMany([1, 2, 3])
await notes.deleteMany(allIds) // remove all known ids
put()
put(data: T & { id?: ID }): Promise<Model<T> & T>
Upsert — updates if id exists, creates otherwise.
// Create with specific id (upsert)
await notes.put({ id: 42, title: "Hello", body: "..." })
// Update if exists, create if not
await notes.put({ id: 42, title: "Updated title" })
count()
count(): Promise<number>
Returns the total number of records.
query()
query(): QueryBuilder<T>
Returns a new QueryBuilder for this collection.
onChange()
onChange(callback: (event: ChangeEvent) => void): () => void
Subscribes to changes on this collection only. Returns an unsubscribe function.
How is this guide?
Last updated on Jun 20, 2026