From 61b3d28b58ec4ed87bb4566d0b22528e2af863ed Mon Sep 17 00:00:00 2001 From: dotansimha Date: Tue, 24 Jan 2017 19:50:50 +0200 Subject: [PATCH] Step 10.7: Add search pattern to the publication --- server/publications.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/server/publications.ts b/server/publications.ts index e8b2511..1974dad 100644 --- a/server/publications.ts +++ b/server/publications.ts @@ -3,16 +3,29 @@ import { Mongo } from 'meteor/mongo'; import { Chats, Messages, Users } from '../imports/collections'; import { Chat, Message, User } from '../imports/models'; -Meteor.publish('users', function(): Mongo.Cursor { +Meteor.publishComposite('users', function( + pattern: string +): PublishCompositeConfig { if (!this.userId) { return; } - return Users.collection.find({}, { - fields: { - profile: 1 + let selector = {}; + + if (pattern) { + selector = { + 'profile.name': { $regex: pattern, $options: 'i' } + }; + } + + return { + find: () => { + return Users.collection.find(selector, { + fields: { profile: 1 }, + limit: 15 + }); } - }); + }; }); Meteor.publish('messages', function(