meteor-pubsublisted
Install: claude install-skill meteor/agent-skills
# Meteor publications and subscriptions
Publications stream a set of documents to subscribed clients and keep them
live. The publication is the only place server-side authorization can
filter rows before they reach the client.
## Decision flow
1. Does the client need this data reactively? If no, prefer a method (one-shot
read). If yes, use a publication.
2. Is the data user-specific? Filter by `this.userId` inside the publish
function. Without that filter, documents leak across users.
3. Can the publication be expressed as a single cursor? Return it directly.
4. Does it need one async lookup before choosing a cursor? Use an async
publish handler, await the lookup, then return the cursor.
5. Does it need per-document async joins, custom aggregation output, or an
external reactive source? Drop to the low-level `this.added` /
`this.changed` / `this.removed` API.
## Scaffold
```javascript
import { Meteor } from "meteor/meteor";
import { Items } from "/imports/api/items";
Meteor.publish("items.mine", function () {
if (!this.userId) {
return this.ready();
}
return Items.find(
{ ownerId: this.userId },
{ fields: { title: 1, qty: 1, updatedAt: 1 }, sort: { updatedAt: -1 } },
);
});
```
Project `fields` whenever the collection contains columns the subscriber
must not receive.
Async publish handlers may also return a cursor:
```javascript
Meteor.publish("items.byTeam", async function (teamId) {
const member = await Memberships.findOneAsync(