Trong collection listingsAndReviews, lọc listing có beds >= 5, sắp xếp theo beds giảm dần (nếu bằng nhau thì theo name tăng dần), lấy 5 listing đầu tiên, sau đó project∗∗chỉin‘name‘,‘beds‘,‘price‘(∗∗kho^ng∗∗in‘id‘).Pipeline:∗∗match + sort+limit + $project.
Chương trình chỉ in kết quả của một câu lệnh aggregate.
Collection listingsAndReviews (dữ liệu mẫu sample_airbnb.listingsAndReviews) đã được nạp sẵn vào database hiện tại. Không cần lệnh use.
Kết quả aggregate theo định dạng mongosh: mảng 5 document dạng { name: '...', beds: ..., price: Decimal128('...') }, theo thứ tự beds giảm dần rồi name tăng dần.
Ví dụ:
Đầu vào:
sample_airbnb.listingsAndReviews
Đầu ra:
[
{ name: 'Venue Hotel Old City', beds: 25, price: Decimal128('227.00') },
{
name: 'LUXURY HOUSE IN BARRA DA TIJUCA',
beds: 18,
price: Decimal128('5502.00')
},
{ name: 'Casa de Vilela', beds: 16, price: Decimal128('500.00') },
{
name: 'Excellent Location and price !',
beds: 16,
price: Decimal128('2083.00')
},
{
name: 'Barra da Tijuca beach house',
beds: 15,
price: Decimal128('5595.00')
}
]Đang tải editor...