-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
65 lines (55 loc) · 1.34 KB
/
main.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {Meteor} from 'meteor/meteor';
import {Mongo} from "meteor/mongo";
import {createQuery} from 'meteor/cultofcoders:grapher';
import moment from 'moment';
Meteor.startup(() => {
// Create mongoDB collections
Book = new Mongo.Collection('Book');
Author = new Mongo.Collection('Author');
// Clean DB
Book.remove({});
Author.remove({});
// Insert elements for testing
let id = Author.insert({
name: "author"
});
Book.insert({
authorId: id,
name: "book",
});
// Create links
Book.addLinks({
'author': {
type: "one",
collection: Author,
field: 'authorId',
}
});
Author.addLinks({
'books': {
collection: Book,
inversedBy: "author",
}
});
// Create Query
let grapherQueryOne = createQuery('grapherQueryOne', {
Book: {
name: 1,
authorId: 1,
author: {
name: 1,
},
}
});
let grapherQueryTwo = createQuery('grapherQueryTwo', {
Book: {
name: 1,
author: {
name: 1,
},
authorId: 1,
}
});
console.log("grapherQueryOne", grapherQueryOne.fetch());
console.log("grapherQueryTwo", grapherQueryTwo.fetch());
});