Skip to main content

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:
  1. Runs on the server when a client subscribes
  2. Returns MongoDB cursors or uses low-level API calls
  3. Sends initial data to the client
  4. Monitors for changes and sends updates automatically
  5. 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:

Performance Optimization

Use Indexes

Limit Published Data

Use Field Projection

Testing Publications