-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildDatabase.js
More file actions
198 lines (166 loc) · 3.6 KB
/
BuildDatabase.js
File metadata and controls
198 lines (166 loc) · 3.6 KB
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
188
189
190
191
192
193
194
195
196
// Admin
// Warning: Running This Script Will Change Root Password!
// Warning: Running This Script Will Reset Database.MediaCollection!
// Warning: All Users Has Execute Rights In This Schema!
// select db
use mediacollection
// clear it
db.dropDatabase()
// needed to do again after drop?
use mediacollection
// TODO: INSERT Admin into Acount!
// make collections
// TODO: Make ref. to account ? if login is supposed to be available
//Create User, Contains password and username for use in the post-review/post-rating procedures.
db.createCollection("Account")
// These test accounts are used in the creation of new Media/Reviews/Ratings
db.Account.insert({Name : 'MrFoo', User : 'Foo'})
db.Account.insert({Name : 'MrsBar', User : 'Bar')
// Use this account to log in during development, it has no preset reviews/ratings.
db.Account.insert({Name : 'User42', User : 'User'})
db.createCollection("Media")
// Create Movie/Album
db.Media.insert({
Title : "Rosenrot",
Creator : [
{Name: "Rammstein"}
],
Genre : "Rammstyle",
Year : "2009",
Review : [
{
User : "Bar",
Title : "Excellent!",
Text : "With deep flavor and class..." ,
Mediatype : "Album"
},
{
User : "Foo",
Title : "Supberb.",
Text : "Very Good. Such Wack.",
Mediatype : "Album"
}
],
Rating : [
{User: "Foo", Score : "1"},
{User: "Bar", Score : "5"}
], // calc. avg. in app, prevent entering wrong values and duplicated users!
AddedBy : "Foo",
Mediatype : "Album"
})
db.Media.ensureIndex( { Title: 1 } )
db.Media.ensureIndex( { Mediatype_Id: 1 } )
// Ref 2 who added it!
db.Media.insert({
Title : "Reise, Reise",
Creator : [
{Name: "Rammstein"}
],
Genre : "Rammstyle",
Year : "2006",
Review : [
{
User : "Bar",
Title : "Extraordinary!",
Text : "This album.. !!!",
Mediatype : "Album"
},
{
User : "Foo",
Title : "Awesome.",
Text : "Can NOT have enough.",
Mediatype : "Album"
}
],
Rating : [
{User: "Foo", Score : "5"},
{User: "Bar", Score : "5"}
],
AddedBy : "Bar",
Mediatype : "Album"
})
db.Media.insert({
Title : "Imagine",
Creator : [
{Name: "John Lennon"}
],
Genre : "Lennstyle",
Year : "2006",
Review : [
{
User : "Bar",
Title : "Its good.",
Text : "I liked this album.",
Mediatype : "Album"
},
{
User : "Foo",
Title : "Eeeh.",
Text : "I dunn get it.",
Mediatype : "Album"
}
],
Rating : [
{User: "Foo", Score : "3"},
{User: "Bar", Score : "4"}
],
AddedBy : "Bar",
Mediatype : "Album"
})
db.Media.insert({
Title : "Chipmunks",
Creator : [
{Name: "Alvin"}
],
Genre : "Chipcore",
Year : "2014",
Review : [
],
//Rating : [
//],
AddedBy : "Bar",
Mediatype : "Album"
})
db.Media.insert({
Title : "Lord ot. Rings",
Creator : [
{Name: "Peter Jackson"}
],
Genre : "Balrogs",
Year : "2006",
Duration : "228",
Review : [
],
//Rating : [
//],
AddedBy : "Bar",
Mediatype : "Movie"
})
// show what has been made
//show collections
// rm users
db.dropAllUsers()
// Create a database user with read access for every normal user, the user does not need to supply
// Login credentials when reading from the database. Login information will be sent when required by the
// Database, when creating a review or rating.
// make user for clientapp
// TODO sync privlieges
db.createUser(
{
user: "clientapp",
pwd: "qwerty",
roles: [
{ role: "read", db: "mediacollection" },
{ role: "readWrite", db: "mediacollection" }
]
}
)
// list users
db.getUsers()
// show what has been mde
//show collections
//show users
//db.getUsers()
//show roles
//show profile
//show dbs