1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45import { Meteor } from 'meteor/meteor'
import { LinksCollection } from '/imports/api/links'
async function insertLink({ title, url }) {
await LinksCollection.insertAsync({ title, url, createdAt: new Date() })
}
Meteor.publish('links.all', () => {
return LinksCollection.find()
})
Meteor.methods({
'links.reverse-title': async function (linkId) {
const { title } = await LinksCollection.findOneAsync(linkId)
await LinksCollection.updateAsync(linkId, {
$set: { title: title.split('').reverse().join('') },
})
},
})
Meteor.startup(async () => {
// If the Links collection is empty, add some data.
if (await LinksCollection.find().countAsync() === 0) {
await insertLink({
title: 'Do the Tutorial',
url: 'https://svelte-tutorial.meteor.com/',
})
await insertLink({
title: 'Follow the Guide',
url: 'https://guide.meteor.com',
})
await insertLink({
title: 'Read the Docs',
url: 'https://docs.meteor.com',
})
await insertLink({
title: 'Discussions',
url: 'https://forums.meteor.com',
})
}
})