Cloud Functions Database API
Complete guide to querying and managing data in your CocoBase cloud functions.Overview
The Database API provides a powerful, MongoDB-like query interface for your PostgreSQL database with automatic relationship detection and advanced filtering capabilities.Key Features
- Advanced Querying - 12+ operators (eq, ne, lt, gt, contains, in, etc.)
- Complex Logic - OR/AND combinations with grouping
- Auto Relationships - Automatically detects users vs collections
- Deep Population - Nested relationship loading (author.company.location)
- Relationship Filtering - Filter by related data (author.role=admin)
- User Relationships - Followers, friends, teams support
- Zero Configuration - No manual relationship definitions needed
Quick Start
Basic Query
Query with Population
Advanced Filtering
Query Operations
query() - Query Collection
Query documents with filters, population, sorting, and pagination.collection_name- Name of the collection to querypopulate- List of relationship fields to populateselect- List of fields to return (optional, returns all by default)sort- Field name to sort byorder- Sort order: “asc” or “desc” (default: “asc”)limit- Maximum number of documents to return (default: 10)offset- Number of documents to skip for pagination (default: 0)**filters- Dynamic filter parameters using operators
find_one() - Get Single Document
Get a single document matching filters.None if not found
Example:
query_users() - Query Users
Query users with the same powerful features as collections.find_user() - Get Single User
Find a single user by ID or filters.Comparison Operators
Use operator suffixes to filter data:| Operator | Suffix | Example | Description |
|---|---|---|---|
| Equal | (none) or _eq | status="published" | Exact match |
| Not Equal | _ne | status_ne="draft" | Not equal |
| Greater Than | _gt | price_gt="100" | Greater than |
| Greater or Equal | _gte | age_gte="18" | Greater than or equal |
| Less Than | _lt | price_lt="1000" | Less than |
| Less or Equal | _lte | stock_lte="10" | Less than or equal |
| Contains | _contains | title_contains="python" | String contains (case-insensitive) |
| Starts With | _startswith | name_startswith="john" | String starts with |
| Ends With | _endswith | email_endswith="@gmail.com" | String ends with |
| In Array | _in | status_in="published,draft" | Value in comma-separated list |
| Not In Array | _notin | category_notin="spam,nsfw" | Value not in list |
| Is Null | _isnull | deleted_at_isnull="true" | Check if field is null/not null |
Examples
Greater Than:Boolean Logic
Simple OR Queries
Use[or] prefix to create OR conditions:
Named OR Groups
Create multiple independent OR groups:Search Across Multiple Fields
Next Steps
- Environment - Learn about request/response handling
- Quick Reference - Cheat sheet for common patterns
- Examples - Real-world code examples
