-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgenerateData.js
187 lines (176 loc) · 5.63 KB
/
generateData.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
"use strict";
function getPreviousWeek(originalDate) {
var lastWeek = new Date(originalDate.getFullYear(), originalDate.getMonth(), originalDate.getDate() - 7);
return lastWeek;
}
function getFollowingWeek(originalDate) {
var nextWeek = new Date(originalDate.getFullYear(), originalDate.getMonth(), originalDate.getDate() + 7);
return nextWeek;
}
var now = ISODate(),
userIds = [],
eventIds = [];
db = connect('localhost:27017/flintandsteel-dev');
// create collections
db.createCollection('users');
db.createCollection('ideas');
db.createCollection('comments');
db.createCollection('events');
// create users
var insertResult = db.users.insert(
[
{
firstName: 'Guybrush',
lastName: 'Threepwood',
fullName: 'Guybrush Threepwood',
username: 'test1',
email: '[email protected]',
nickname: 'Threepy',
title: 'Hippy Lumberjack'
},
{
firstName: 'Rick',
lastName: 'Sanchez',
fullName: 'Rick Sanchez',
username: 'test2',
email: '[email protected]',
nickname: 'Dirty',
title: 'Street Pharmacist'
},
{
firstName: 'Dick',
lastName: 'Dickerson',
fullName: 'Dick Dickerson',
username: 'test3',
email: '[email protected]',
nickname: 'The Fracker',
title: 'Money Bags Oil Man'
},
{
firstName: 'Test',
lastName: 'testerson',
fullName: 'Test Testerson',
username: 'test4',
email: '[email protected]',
nickname: 'The Tester',
title: 'Testin\' All Day'
}
]
);
print('INSERT RESULT: Inserted ' + insertResult.nInserted + ' documents into users collection.');
// get the user ids
db.users.find({}, { _id: 1 }).forEach(function(user) {
userIds.push(user._id);
});
// create events
insertResult = db.events.insert(
[
{
name: 'In Progress Event 1',
location: 'USMAY',
startDate: now,
endDate: getFollowingWeek(now)
},
{
name: 'In Progress Event 2',
location: 'USMKE',
startDate: now,
endDate: getFollowingWeek(now)
},
{
name: 'Completed Event 1',
location: 'USTWB',
startDate: getPreviousWeek(getPreviousWeek(now)),
endDate: getPreviousWeek(now)
}
]
);
print('INSERT RESULT: Inserted ' + insertResult.nInserted + ' documents into events collection.');
// get the event ids
db.events.find({}, { _id: 1 }).forEach(function(user) {
eventIds.push(user._id);
});
// create ideas
insertResult = db.ideas.insert(
[
{
title: 'Guybrush\'s Test Idea',
description: 'Nihil enim iam habes, quod ad corpus referas; Tibi hoc incredibile, quod beatissimum. A mene tu? Quod cum accidisset ut alter alterum',
authorId: userIds[0],
eventId: eventIds[0],
timeCreated: now,
timeModified: now,
tags: [],
rolesreq: [],
likes: [],
updates: [],
comments: [],
backs: [{
_id: new ObjectId(),
text: 'Idea Owner',
authorId: userIds[0],
timeCreated: ISODate(),
types: [{ name: 'Owner', _lowername: 'owner' }]
}],
team: [{ _id: new ObjectId(), memberId: userIds[0] }],
complexity: []
},
{
title: 'Rick\'s Test Idea',
description: 'This is Mr. Sanchez\'s brilliant idea.',
authorId: userIds[1],
eventId: eventIds[1],
timeCreated: now,
timeModified: now,
tags: [],
rolesreq: [],
likes: [],
updates: [],
comments: [],
backs: [{
_id: new ObjectId(),
text: 'Idea Owner',
authorId: userIds[1],
timeCreated: ISODate(),
types: [{ name: 'Owner', _lowername: 'owner' }]
}],
team: [{ _id: new ObjectId(), memberId: userIds[1] }],
complexity: [{
stars: [{filled: true}, {filled: true}, {filled: true}, {filled: true}, {filled: false}],
value: 4,
authorId: userIds[1]
},{
stars: [{filled: true}, {filled: true}, {filled: false}, {filled: false}, {filled: false}],
value: 2,
authorId: userIds[0]
}]
},
{
title: 'Dick\'s Test Idea',
description: 'This is "The Fracker\'s" master plan.',
authorId: userIds[2],
eventId: eventIds[2],
timeCreated: now,
timeModified: now,
tags: [],
rolesreq: [],
likes: [],
updates: [],
comments: [],
backs: [{
_id: new ObjectId(),
text: 'Idea Owner',
authorId: userIds[2],
timeCreated: ISODate(),
types: [{ name: 'Owner', _lowername: 'owner' }]
}],
team: [{ _id: new ObjectId(), memberId: userIds[2] }],
complexity: [{
stars: [{filled: true}, {filled: true}, {filled: false}, {filled: false}, {filled: false}],
value: 2,
authorId: userIds[0]
}]
}
]
);
print('INSERT RESULT: Inserted ' + insertResult.nInserted + ' documents into ideas collection.');