-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw_2.js
81 lines (67 loc) · 1.81 KB
/
hw_2.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
db = db.getSiblingDB('competitions')
comp1 = {
compName: 'Burgas2015',
place: 'Borisova gradina Burgas',
distanceWinner: {
'2km':['Peter Petrov'],
'42km':['Ivan ivanov'],
'10km': ['Todor Todorov']
},
participants: 10
}
comp2 = {
compName: 'Burgas2015',
place: 'South park Burgas',
distanceWinner: {
'2km':['Georgi Georgiev', 'Georgi Ivanov'],
'5km':['Ivan ivanov'],
'10km': ['Todor Todorov']
},
participants: 20
}
comp3 = {
compName: 'Sofia2015',
place: 'South park Burgas',
distanceWinner: {
'2km':['Georgi Georgiev', 'Maria Ivanova', 'Georgi Ivanov'],
'5km':['Ivan ivanov'],
'10km': ['Todor Todorov']
},
duration : '3 hours',
participants: 50
}
comp4 = {
compName: 'Burgas2014',
place: 'Borisova Burgas',
distanceWinner: {
'2km':['Georgi Georgiev', 'Georgi Ivanov'],
'5km':['Ivan ivanov'],
'10km': ['Todor Todorov']
},
participants: 18,
sponsor: 'Astea'
}
comp5 = {
compName: 'Burgas2015',
place: 'North park Burgas',
distanceWinner: {
'42km':['Georgi Georgiev', 'Georgi Ivanov'],
'2km':['Peter Petrov'],
'5km':['Ivan ivanov'],
'10km': ['Todor Todorov']
},
participants: 23,
sponsor: 'FMI'
}
//0.
db.runCompetitions.insert([comp1, comp2, comp3, comp4, comp5])
//1. Three competitions with the most participants
db.runCompetitions.find({place: /Burgas/}).sort({participants:-1}).limit(3).pretty()
//2.
db.runCompetitions.update( {"distanceWinner.42km" :{ $exists: true }}, {"$set": {maraton:true}}, {multi: true})
//3. remove
db.runCompetitions.remove({ $or : [{"distanceWinner.2km" : /Peter Petrov/}, {"distanceWinner.2km" : /Maria Ivanova/}]})
//4.Add distance of 5 km
db.runCompetitions.update( {"sponsor" :{ $exists: true }}, {"$push": { "distanceWinner.5km" : ["Georgi Georgiev"] }})
//To start script
// load("fn61559_zad2.js")