Trong collection comments, sắp xếp comment theo date giảm dần, lấy 5 comment mới nhất. Pipeline: sort+limit (kèm $project). Chỉ in hai trường name, date (không in _id).
Chương trình chỉ in kết quả của một câu lệnh aggregate.
Collection comments (dữ liệu mẫu sample_mflix.comments) đã đượ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, mỗi document dạng { name: ..., date: ISODate(...) }, theo thứ tự date giảm dần.
Ví dụ:
Đầu vào:
sample_mflix.comments
Đầu ra:
[
{ name: 'sxkybvzb6', date: ISODate('2018-08-14T15:05:03.142Z') },
{ name: 'jjjdmntww', date: ISODate('2018-08-14T15:03:14.306Z') },
{ name: 'yznjm1yul', date: ISODate('2018-08-14T15:01:16.716Z') },
{ name: 'sg1u6swo4', date: ISODate('2018-08-14T15:00:25.211Z') },
{ name: 'g7pnd0yy2', date: ISODate('2018-08-14T14:53:11.550Z') }
]Đang tải editor...