Skip to content

Commit 5ff94ff

Browse files
dotansimhadarkbasic
authored andcommitted
Step 10.7: Add search pattern to the publication
1 parent 8c8dfd5 commit 5ff94ff

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

‎api/server/publications.ts‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@ import { Users } from './collections/users';
33
import { Messages } from './collections/messages';
44
import { Chats } from './collections/chats';
55

6-
Meteor.publish('users', function(): Mongo.Cursor<User> {
6+
Meteor.publishComposite('users', function(
7+
pattern: string
8+
): PublishCompositeConfig<User> {
79
if (!this.userId) {
810
return;
911
}
1012

11-
return Users.collection.find({}, {
12-
fields: {
13-
profile: 1
13+
let selector = {};
14+
15+
if (pattern) {
16+
selector = {
17+
'profile.name': { $regex: pattern, $options: 'i' }
18+
};
19+
}
20+
21+
return {
22+
find: () => {
23+
return Users.collection.find(selector, {
24+
fields: { profile: 1 },
25+
limit: 15
26+
});
1427
}
15-
});
28+
};
1629
});
1730

1831
Meteor.publish('messages', function(

0 commit comments

Comments
 (0)