JavaScript SDK
Complete guide to using Cocobase with JavaScript and TypeScript applications.Installation
npm:Quick Start
Initialize Cocobase
Basic Operations
Batch Operations
Counting & Aggregation
Querying Data
Simple Filters
Operators Reference
Comparison Operators
| Operator | Filter Key | Example |
|---|---|---|
| Equal | field | { status: "active" } |
| Greater Than | field__gt | { age__gt: 18 } |
| Greater or Equal | field__gte | { age__gte: 18 } |
| Less Than | field__lt | { age__lt: 65 } |
| Less or Equal | field__lte | { age__lte: 65 } |
| Not Equal | field__ne | { status__ne: "deleted" } |
String Operators
| Operator | Filter Key | Example |
|---|---|---|
| Contains | field__contains | { title__contains: "javascript" } |
| Starts With | field__startswith | { email__startswith: "admin" } |
| Ends With | field__endswith | { domain__endswith: ".com" } |
Array Operators
| Operator | Filter Key | Example |
|---|---|---|
| In Array | field__in | { status__in: "active,pending" } |
| Not In Array | field__notin | { status__notin: "deleted,archived" } |
Sorting and Pagination
Sorting
Pagination
Type Safety with TypeScript
Define Your Types
Create Typed Documents
Authentication
Email/Password
OAuth
Advanced Authentication
Auth Event Callbacks
Google OAuth
GitHub OAuth
Role Checking
List Users
Get User By ID
Password Reset
Email Verification
Two-Factor Authentication (2FA)
Real-time Data
Watch a Collection
Project Broadcast
Room Chat
Multiplayer Game
Initialize Game Client
Connect to a Room
Listen for Events
One-time Event Listener
Remove Event Listeners
Send Actions to Server
Check Connection Status
Disconnect
Auto-Reconnect
List Game Rooms
List Rooms
File Storage
Error Handling
Best Practices
1. Always Use Types
2. Always Set Limits
3. Handle Errors
4. Use Environment Variables
Next Steps
- Flutter SDK - Learn about the Flutter SDK
- Authentication - Deep dive into auth
- Querying - Advanced query techniques
- Real-time - Real-time data synchronization
