Trong collection theaters, sắp xếp các rạp theo theaterId tăng dần, chỉ in theaterId và location.address.zipcode (không in _id), lấy 5 bản ghi đầu tiên. Pipeline: sort+project + $limit.
Giữ nguyên cấu trúc lồng của trường zipcode (dùng projection "location.address.zipcode": 1, không đổi tên trường). Chương trình chỉ in kết quả của một câu lệnh aggregate.
Collection theaters (dữ liệu mẫu sample_mflix.theaters) đã đượ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
{ theaterId: ..., location: { address: { zipcode: '...' } } }
theo thứ tự theaterId tăng dần.
Ví dụ:
Đầu vào:
sample_mflix.theaters
Đầu ra:
[
{ theaterId: 4, location: { address: { zipcode: '55305' } } },
{ theaterId: 6, location: { address: { zipcode: '55077' } } },
{ theaterId: 7, location: { address: { zipcode: '55113' } } },
{ theaterId: 8, location: { address: { zipcode: '55337' } } },
{ theaterId: 10, location: { address: { zipcode: '55109' } } }
]Đang tải editor...