Skip to content

Commit

Permalink
Step 10.7: Add search pattern to the publication
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Mar 23, 2017
1 parent 8693a53 commit b20cd11
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions api/server/publications.ts
Expand Up @@ -3,16 +3,29 @@ import { Users } from './collections/users';
import { Messages } from './collections/messages';
import { Chats } from './collections/chats';

Meteor.publish('users', function(): Mongo.Cursor<User> {
Meteor.publishComposite('users', function(
pattern: string
): PublishCompositeConfig<User> {
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(
Expand Down

0 comments on commit b20cd11

Please sign in to comment.