Overview
Publications are Meteor’s way of sending data from the server to clients. They define what data clients can access and automatically keep that data synchronized in real-time through DDP (Distributed Data Protocol).
How Publications Work
A publication:
- Runs on the server when a client subscribes
- Returns MongoDB cursors or uses low-level API calls
- Sends initial data to the client
- Monitors for changes and sends updates automatically
- Cleans up when the client unsubscribes
Defining Publications
Basic Publication
Publication with Parameters
User-Specific Publications
Always call this.ready() when not returning a cursor to signal that initial data has been sent.
Publishing Multiple Collections
Publication Context
Inside a publication function, this provides:
Subscribing to Publications
Basic Subscription
Subscription with Parameters
Reactive Subscriptions in Blaze
Subscriptions in React
Low-Level Publish API
For complete control over published data:
Publishing from External Data Sources
Security and Validation
Always Validate Parameters
Check User Permissions
Field Filtering
Never publish sensitive fields like password hashes or API tokens.
Publication Strategies
Different strategies for different use cases:
SERVER_MERGE (Default)
Server maintains a copy of all subscribed data:
NO_MERGE
No delta tracking, just ID tracking:
Reactive Joins
Using reywood:publish-composite:
Counting Records
Using tmeasday:publish-counts:
Use Indexes
Limit Published Data
Use Field Projection
Testing Publications