Reference
CRUD API
Collection CRUD operations — find, findOne, create, update, delete, count.
All collections expose these CRUD operations on both server and client.
find(options)
const result = await collections.posts.find({
where?: { ... },
orderBy?: { field: "asc" | "desc" },
limit?: number,
offset?: number,
with?: { relation: true },
select?: { field: true },
});Returns: { docs: T[], totalDocs: number }
findOne(options)
const record = await collections.posts.findOne({
where: { id: "abc" },
with?: { ... },
select?: { ... },
});Returns: T | null
create(data)
const record = await collections.posts.create({
title: "Hello",
body: "World",
status: "draft",
});Returns: T (created record)
update(options)
const record = await collections.posts.update({
where: { id: "abc" },
data: { status: "published" },
});Returns: T (updated record)
delete(options)
await collections.posts.delete({
where: { id: "abc" },
});count(options)
const count = await collections.posts.count({
where: { status: "published" },
});Returns: number
updateMany(options)
await collections.posts.updateMany({
where: { status: "draft" },
data: { status: "archived" },
});deleteMany(options)
await collections.posts.deleteMany({
where: { status: "archived" },
});Client API
Same methods available on client.collections.*:
const posts = await client.collections.posts.find({ ... });
const post = await client.collections.posts.findOne({ ... });
const created = await client.collections.posts.create({ ... });
const updated = await client.collections.posts.update({ id: "abc", data: { ... } });
await client.collections.posts.delete({ id: "abc" });
const count = await client.collections.posts.count({ ... });Upload Methods
For upload collections:
const asset = await client.collections.assets.upload(file, {
onProgress?: (percent: number) => void,
});
const assets = await client.collections.assets.uploadMany(files, {
onProgress?: (percent: number) => void,
});