Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Step 10.7: Add search pattern to the publication
  • Loading branch information
dotansimha authored and darkbasic committed Oct 16, 2017
1 parent 8c8dfd5 commit 5ff94ff
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 5ff94ff

Please sign in to comment.