-
Notifications
You must be signed in to change notification settings - Fork 11
/
Day6P4.js
53 lines (47 loc) · 1.28 KB
/
Day6P4.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
/*
Write a MongoDB query to display student names who has an attendance percentage
between 85 and 95 (inclusive)
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(
{
attendancePercentage:{$gte:85,$lte:95}
},
{_id:0,name:1}));