Advanced Operations
Unlock the full power of CocoBase with batch operations, aggregations, transactions, and advanced data processing techniques.Batch Operations
Handle multiple documents efficiently with batch operations. Available across all SDKs.Batch Create
Create multiple documents in a single request:- Flutter
- JavaScript
- Python
- Go
Batch Update
Update multiple documents at once:- Flutter
- JavaScript
- Python
Batch Delete
Delete multiple documents efficiently:- Flutter
- JavaScript
- Python
- Go
Best Practices for Batch Operations
Process Large Datasets in Chunks:Count Documents
Efficiently retrieve the number of documents in a collection matching a filter.- JavaScript
- Flutter
- Python
Aggregations
Calculate statistics across your data efficiently.Sum
Calculate total of a field:- Flutter
- JavaScript
- Python
Average
Calculate average value:- Flutter
- JavaScript
- Python
Min/Max
Find minimum and maximum values:- JavaScript
- Flutter
- Python
Aggregations with Filters
Calculate statistics on filtered data:Real-World Aggregation Examples
Statistics Dashboard:Group By
Group documents by field values and get counts. Note:groupByField is available in Flutter and Python SDKs only. It is not available in the JavaScript SDK.
Basic Grouping
- Flutter
- Python
Group With Filters
Grouping Patterns
Dashboard Statistics:Transactions
Handle multiple operations atomically (availability depends on your backend).Client-Side Transaction Pattern
Performance Optimization
1. Use Indexes
Create indexes on frequently queried fields:- Index fields used in
whereclauses - Index fields used for sorting
- Don’t over-index (impacts write performance)
- Avoid indexing large text fields
2. Pagination
Always paginate large datasets:3. Caching
Implement client-side caching to reduce API calls:4. Select Specific Fields
Only fetch needed fields to reduce bandwidth:- JavaScript
- Flutter
5. Lazy Loading
Load data on demand:Caching Strategies
Memory Cache
Local Storage Cache (Browser/Flutter)
Indexing Best Practices
When to Index
- Fields used frequently in
whereclauses - Fields used for sorting
- Fields used in relationships
- Fields with high cardinality (many unique values)
When NOT to Index
- Large text fields
- Fields that change frequently
- Low cardinality fields (few unique values like boolean)
- Fields rarely queried
Example Index Strategy
Type Conversion and Type Safety
Flutter Type-Safe Models
JavaScript Type Safety with TypeScript
Custom Data Models
Nested Objects
Polymorphic Types
Monitoring and Debugging
Query Performance Measurement
Request Logging
Deprecated Methods
[!WARNING] The followings methods called directly on thedbinstance are deprecated. Use thedb.authnamespace instead to ensure compatibility with future SDK versions and to access the latest security features.
db.login()→ Usedb.auth.login()db.register()→ Usedb.auth.register()db.logout()→ Usedb.auth.logout()db.isAuthenticated()→ Usedb.auth.isAuthenticated()db.getCurrentUser()→ Usedb.auth.getCurrentUser()
Next Steps
- Best Practices - Security and optimization tips
- Troubleshooting - Common issues and solutions
- Cloud Functions - Build serverless functions
- Real-time - Add live data synchronization
