Filtering
Filtering, sorting, and pagination guide
Filtering
A filtering reference for use with the SDK and REST API.
Pagination
const { docs, totalDocs, totalPages, hasNextPage } = await client.from('products').find({
page: 1,
limit: 20,
})Sorting
await client.from('products').find({ sort: 'price' }) // Ascending
await client.from('products').find({ sort: '-createdAt' }) // Descending
await client.from('products').find({ sort: '-status,price' }) // Multiple sortWhere Operators
| Operator | Description | Example |
|---|---|---|
equals | Equal to | { status: { equals: 'active' } } |
not_equals | Not equal to | { status: { not_equals: 'archived' } } |
greater_than | Greater than | { price: { greater_than: 10000 } } |
greater_than_equal | Greater than or equal to | { price: { greater_than_equal: 10000 } } |
less_than | Less than | { stock: { less_than: 100 } } |
less_than_equal | Less than or equal to | { stock: { less_than_equal: 100 } } |
in | In list | { status: { in: ['active', 'draft'] } } |
not_in | Not in list | { status: { not_in: ['archived'] } } |
like | Partial match | { title: { like: 'shirt' } } |
contains | Array contains | { tags: { contains: 'featured' } } |
exists | Field exists | { thumbnail: { exists: true } } |
Logical Operators
AND
await client.from('products').find({
where: {
and: [
{ status: { equals: 'active' } },
{ price: { greater_than: 10000 } },
]
}
})OR
await client.from('products').find({
where: {
or: [
{ status: { equals: 'active' } },
{ status: { equals: 'featured' } },
]
}
})Compound Conditions
await client.from('products').find({
where: {
and: [
{ status: { equals: 'active' } },
{
or: [
{ price: { less_than: 10000 } },
{ tags: { contains: 'sale' } },
]
}
]
}
})Relationship Filtering
// Products in a specific category
await client.from('products').find({
where: { categories: { equals: 'category-id' } }
})
// Filter by relationship field property
await client.from('products').find({
where: { 'category.slug': { equals: 'electronics' } }
})Date Filtering
await client.from('posts').find({
where: {
publishedAt: {
greater_than: '2024-01-01T00:00:00.000Z',
less_than: new Date().toISOString(),
}
}
})