Skip to main content

Filtering Guide

Cocobase provides a powerful, MongoDB-inspired query interface for your documents. You can filter, search, sort, and paginate using simple URL parameters or SDK method calls.

Query Operators

Use operator suffixes on field names to perform advanced comparisons.
OperatorSuffixExampleDescription
Equal(none)status=publishedExact match
Not Equal__nestatus__ne=draftNot equal
Greater Than__gtprice__gt=100Greater than
Greater or Equal__gteage__gte=18Greater than or equal
Less Than__ltprice__lt=1000Less than
Less or Equal__ltestock__lte=10Less than or equal
Contains__containstitle__contains=helloCase-insensitive search
Starts With__startswithname__startswith=john
Ends With__endswithemail__endswith=.com
In Array__instatus__in=a,bValue in comma-separated list
Not In Array__notinstatus__notin=c,dValue not in list
Is Null__isnulldeleted__isnull=trueCheck if field is null

Boolean Logic

AND Queries (Implicit)

By default, multiple query parameters are combined with AND logic.
# status=active AND role=admin
curl "https://api.cocobase.buzz/collections/users?status=active&role=admin"

OR Queries

Use the [or] prefix to create OR conditions.
# status=published OR featured=true
curl "https://api.cocobase.buzz/collections/posts?[or]status=published&[or]featured=true"

Named OR Groups

Group multiple OR conditions together. Groups are ANDed with other filters.
# category=tech AND (tag=python OR tag=go)
curl "https://api.cocobase.buzz/collections/posts?category=tech&[or:tags]tag=python&[or:tags]tag=go"
Search for a keyword across multiple fields using the __or__ syntax.
# Search 'john' in either 'name' OR 'email'
curl "https://api.cocobase.buzz/collections/users?name__or__email__contains=john"

Sorting and Pagination

Sorting

  • orderBy: The field name to sort by.
  • order: Use asc (ascending) or desc (descending).
curl "https://api.cocobase.buzz/collections/posts?orderBy=createdAt&order=desc"

Pagination

  • limit: Number of items to return (default 20, max 100).
  • offset: Number of items to skip.
curl "https://api.cocobase.buzz/collections/posts?limit=10&offset=20"

Relationships (Population)

Fetch related documents in a single request using the populate parameter.

Single Population

curl "https://api.cocobase.buzz/collections/posts?populate=author"

Nested Population

curl "https://api.cocobase.buzz/collections/posts?populate=author.company.location"
# Get posts where author's role is admin
curl "https://api.cocobase.buzz/collections/posts?author.role=admin&populate=author"

Complete Examples

Complex E-Commerce Query

Get available products in ‘electronics’ between 100100-500, sorted by price.
const params = new URLSearchParams({
  category: 'electronics',
  status: 'available',
  price__gte: '100',
  price__lte: '500',
  orderBy: 'price',
  order: 'asc',
  populate: 'brand'
});

const res = await fetch(`https://api.cocobase.buzz/collections/products?${params}`);
Find users matching a search term in name or bio who are verified.
params = {
    'verified': 'true',
    '[or:search]name__contains': 'alice',
    '[or:search]bio__contains': 'alice'
}
res = requests.get('https://api.cocobase.buzz/collections/users', params=params)