Skip to main content

Relationships

Build relational data structures by linking documents and users together with automatic population support across all platforms.
Relationships enable you to structure complex data models like social networks, e-commerce systems, and collaborative applications.

Overview

Cocobase supports powerful relationship features:
  • Document references - Store IDs to link documents
  • Population - Automatically fetch related data
  • Nested population - Multi-level relationship resolution
  • User-to-user relationships - Followers, friends, referrals
  • User-to-document relationships - Bookmarks, favorites, ownership
  • Document-to-document relationships - Comments, reviews, hierarchies

Relationship Types

One-to-One

A single reference to another entity.

One-to-Many / Many-to-Many

Arrays of references for multiple relationships.

Creating Relationships

User to User

User to Document

Document to Document


Populating Relationships

Automatically fetch related data instead of just IDs.

Basic Population

Populate Multiple Fields

Explicit Source Specification

Force population from specific collections or AppUser model.

Social Features

Follow System

Referral System


Best Practices

Population uses optimized batch queries to avoid N+1 problems.
Avoid over-populating to reduce response size and improve performance.
Don’t store thousands of IDs in a single array field.
Combine filters and population for efficient queries.
Cache frequently accessed relationships to reduce API calls.

Next Steps

CRUD Operations

Create and manage related documents

Query & Filtering

Filter documents by relationships

Real-time Updates

Watch relationship changes live

Authentication

Manage user relationships