-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries.js
72 lines (61 loc) · 1.5 KB
/
queries.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
//Find all the topics and tasks which were taught or completed in the month of October:
db.topics.find({ "date_taken": { $gte: "2024-10-01", $lte: "2024-10-31" } })
// Find all the company drives that appeared between 15th October 2024 and 31st October 2024:
db.companydrives.find({ "date": { $gte: "2024-10-15", $lte: "2024-10-31" } })
//Find all the company drives and students who appeared for the placement:
db.companydrives.aggregate([
{
$lookup: {
from: "users",
localField: "userid",
foreignField: "userid",
as: "student"
}
},
{
$project: {
company: 1,
date: 1,
selected: 1,
students: {
$map: {
input: "$student",
as: "stud",
in: "$$stud.name"
}
}
}
}
])
//Find the number of problems solved by each user in codekata:
db.codekata.aggregate([
{
$group: {
_id: "$userid",
total_problems_solved: { $sum: "$problems_solved" }
}
}
])
//Find all the mentors who have mentored more than 15 students:
db.users.aggregate([
{
$group: {
_id: "$mentorallocated",
mentee_count: { $sum: 1 }
}
},
{
$match: {
mentee_count: { $gt: 15 }
}
}
])
//Find the number of users who were absent and did not submit tasks between 15th October 2024 and 31st October 2024:
db.attendance.aggregate([
{
$match: {
"date": { $gte: "2024-10-15", $lte: "2024-10-31" },
"present": false
}
}
])