-
Notifications
You must be signed in to change notification settings - Fork 2
/
10.FindByWhereAndOr.js
81 lines (74 loc) · 1.45 KB
/
10.FindByWhereAndOr.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
//Find by Where and or Operator
db.getCollection("employee").find({
$and: [{ salary: { $gte: 4000 } }, { roll: { $gte: 40 } }],
});
/*
executed result
{
"_id" : ObjectId("6474d74380389505350476ab"),
"name" : "Mohammad",
"salary": 4000,
"roll": 55
}
{
"_id" : ObjectId("6474d74380389505350476a1"),
"name" : "Sujon",
"salary": 4120,
"roll": 40
}
}*/
db.getCollection("employee").find({
$or: [{ $salary: { $gt: 4000 } }, { roll: { $gte: 40 } }],
});
/*
executed result
{
"_id" : ObjectId("6474d74380389505350476ab"),
"name" : "Mohammad",
"salary": 17000,
"roll": 05
}
{
"_id" : ObjectId("6474d74380389505350476a1"),
"name" : "Sujon",
"salary": 1000,
"roll": 190
}
}*/
db.getCollection("employee").aggregate([
{ $match: { $and: [{ $salary: { $gt: 4000 } }, { roll: { $gte: 40 } }] } },
]);
/*
executed result
{
"_id" : ObjectId("6474d74380389505350476ab"),
"name" : "Mohammad",
"salary": 4000,
"roll": 55
}
{
"_id" : ObjectId("6474d74380389505350476a1"),
"name" : "Sujon",
"salary": 4120,
"roll": 40
}
}*/
db.getCollection("employee").aggregate([
{ $match: { $salary: { $gt: 4000 } } },
{ $match: { roll: { $gte: 40 } } },
]);
/*
executed result
{
"_id" : ObjectId("6474d74380389505350476ab"),
"name" : "Mohammad",
"salary": 17000,
"roll": 05
}
{
"_id" : ObjectId("6474d74380389505350476a1"),
"name" : "Sujon",
"salary": 1000,
"roll": 190
}
}*/