diff --git a/v3-docs/docs/community-packages/meteor-rpc.md b/v3-docs/docs/community-packages/meteor-rpc.md index 683a98be16..3c3e5b5554 100644 --- a/v3-docs/docs/community-packages/meteor-rpc.md +++ b/v3-docs/docs/community-packages/meteor-rpc.md @@ -175,6 +175,37 @@ Meteor.publish("chatRooms", function () { ::: +### module.addSharedPublication + +`addSharedPublication(name: string, schema: ZodSchema, handler: (args: ZodTypeInput) => Array> | Promise>> )` + +This is similar to `addPublication`, but it allows you to create an array of cursors, which can be useful for shared queries that need to return multiple collections or different queries. + +```typescript [server/chat.ts] +// server/main.ts +import { createModule } from "meteor-rpc"; +import { ChatCollection } from "/imports/api/chat"; +import { UserCollection } from "/imports/api/user"; +import { z } from "zod"; + +const server = createModule(); +server.addSharedPublication("chatRooms", z.string(), (userId) => { + return [ChatCollection.find({ userId }), UserCollection.find({ userId })]; +}); + +server.build(); +// is the same as +import { Meteor } from "meteor/meteor"; +import { ChatCollection } from "/imports/api/chat"; +import { UserCollection } from "/imports/api/user"; +import { check } from "meteor/check"; + +Meteor.publish("chatRooms", function (userId) { + check(userId, String); + return [ChatCollection.find({ userId }), UserCollection.find({ userId })]; +}); +``` + ### `module.addSubmodule` This is used to add a submodule to the main module, adding namespaces for your methods and publications and making it easier to organize your code.