01 Software

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 sort

Where Operators

OperatorDescriptionExample
equalsEqual to{ status: { equals: 'active' } }
not_equalsNot equal to{ status: { not_equals: 'archived' } }
greater_thanGreater than{ price: { greater_than: 10000 } }
greater_than_equalGreater than or equal to{ price: { greater_than_equal: 10000 } }
less_thanLess than{ stock: { less_than: 100 } }
less_than_equalLess than or equal to{ stock: { less_than_equal: 100 } }
inIn list{ status: { in: ['active', 'draft'] } }
not_inNot in list{ status: { not_in: ['archived'] } }
likePartial match{ title: { like: 'shirt' } }
containsArray contains{ tags: { contains: 'featured' } }
existsField 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(),
    }
  }
})

On this page