-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.js
More file actions
37 lines (37 loc) · 916 Bytes
/
Copy path1.js
File metadata and controls
37 lines (37 loc) · 916 Bytes
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
await Tour.aggregate([
{
$match: { ratingsAverage: { $gte: 4.5 } }
},
{
$group: {
_id: { $toUpper: '$difficulty' },
numTours: { $sum: 1 },
numRatings: { $sum: '$ratingsQuantity' },
avgRating: { $avg: '$ratingsAverage' },
avgPrice: { $avg: '$price' },
minPrice: { $min: '$price' },
maxPrice: { $max: '$price' }
}
},
{
$sort: { avgPrice: 1 }
}
// {
// $match: { _id: { $ne: 'EASY' } }
// }
]);
const stats= await Tour.aggregate([
{
$match:{ratingsAverage:{$gte:4.5}}
},
{
$group:{
_id:null,
// در خط بالا باید فیلدی را بدهیم که میخواهیم با آن گروهبندی کنیم
avgRating:{$avg:'$ratingsAverage'},
avgPrice:{$avg:'$price'},
minPrice:{$min:'$price'},
maxPrice:{$max:'$price'}
}
}
])