-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMongo.js
114 lines (103 loc) · 2.43 KB
/
Mongo.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
// 1. Find all the topics and tasks which are thought in the month of October.
//Tasks
db.Tasks.aggregate([
{ $match: { completed_month: "October" } },
{ $project: { _id: 0, task_name: "$description" } },
]);
//Topics
db.Topics.aggregate([
{ $match: { taught_month: "October" } },
{ $project: { _id: 0, topic_name: "$topic" } },
]);
// 2. Find all the company drives which appeared between 15-oct-2020 and 31-oct-2020
db.Tasks.find(
{
completed_on: {
$gte: "2020-10-15",
$lte: "2020-10-31",
},
},
{
_id: 0,
taskID: 1,
description: 1,
}
);
//3 . Find all the company drives and students who are appeared for the placement.
db.Company.aggregate([
{
$lookup: {
from: "Users",
localField: "students_appeared",
foreignField: "userID",
as: "students",
},
},
{
$project: {
_id: 0,
company_name: 1,
date: 1,
students: "$students.name",
},
},
]);
// 4. find the number of problems solved by the user in codekatta
db.Codekatta.aggregate([
{
$lookup: {
from: "Users", // Join with Users collection
localField: "userID", // Creating Link
foreignField: "userID", // Creatong Link
as: "user_info" // Output array
}
},
{
$unwind: "$user_info" // Unwind the user_info array to get the user details
},
{
$project: {
_id: 0, // Exclude the _id field
userID: 1, // Include the userID field
student_name: "$user_info.name", // Include the student's name
total_problems_solved: "$completed_questions" // Include the total problems solved
}
}
]);
// 5.Find all the mentors with who has the mentee's count more than 15.
db.Mentors.find(
{ users_count: { $gt: 15 } },
{ _id: 0, name: 1, users_count: 1 }
);
//6.Find the number of users who are absent and task is not submitted between 15-oct-2020 and 31-oct-2020
db.Users.aggregate([
{
$match: {
$and: [
{
absent: { $gte: "2020-10-15", $lte: "2020-10-31" } // Check if absent date falls within the range
},
{
tasks_submitted: { $exists: true, $not: { $size: 0 } } // Check if tasks_submitted array exists and is not empty
}
]
}
},
{
$lookup: {
from: "Tasks",
localField: "tasks_submitted",
foreignField: "taskID",
as: "task_info"
}
},
{
$project: {
_id: 0,
name: 1
}
},
{
$count: "num_users"
}
])