-
Notifications
You must be signed in to change notification settings - Fork 11
/
Day6P3.js
58 lines (49 loc) · 1.35 KB
/
Day6P3.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
/*
Write a MongoDB query to display the student name, department and gpa, who took
'Mathematics' department OR those with a GPA less than 3.3
Database: test
Collection: students
Sample Document:
----------------
{
"studentId": "STU001",
"name": "John Doe",
"age": 21,
"gender": "Male",
"department": "Computer Science",
"year": "Senior",
"gpa": 3.7,
"course1": "CS101",
"course2": "CS201",
"course3": "EE101",
"email": "[email protected]",
"phoneNumber": "+1-202-555-0101",
"street": "123 Main St",
"city": "Somewhere",
"state": "NY",
"zipCode": "10001",
"attendancePercentage": 90,
"graduatingYear": 2025,
"scholarship": "Dean's List",
"activity1": "Coding Club",
"activity2": "Soccer"
}
Note:
=====
To write the query, use printjson() method from 'mongosh' module
e.g., To display all the documents from 'employees' collection
from 'test' database.
=> printjson( db.getSiblingDB('test').students.find() )
Where,
db => databse connection object
getSiblingDB('test') => "test" is database name
students => collections name
find => method to retrieve all the matched docuemnts
*/
printjson(db.getSiblingDB('test').students.find({
$or:[
{department:"Mathematics"},
{gpa:{$lt:3.3}}
]
},
{_id:0,name:1,department:1,gpa:1}));