Collection users của dữ liệu mẫu không lưu thời điểm hoạt động (không có trường last_active). Hoạt động của user được ghi lại trong collection comments: mỗi bình luận có name, email của user và date là thời điểm bình luận.
Truy vấn các hoạt động gần đây nhất của user:
• Chỉ xét các bình luận có trường date
• Sắp xếp theo date giảm dần
• Lấy 5 bình luận gần đây nhất
• Chỉ hiển thị name, email, date (không hiển thị _id)
Không cần lệnh use.
Collection comments (dữ liệu mẫu sample_mflix.comments) đã được nạp sẵn.
In ra kết quả của câu lệnh aggregate (chỉ một câu truy vấn này được in): mảng 5 document theo định dạng mongosh, mỗi document có các trường name, email, date, ví dụ một phần tử:
{
name: 'sxkybvzb6',
email: '[email protected]',
date: ISODate('2018-08-14T15:05:03.142Z')
},
Ví dụ:
Đầu vào:
sample_mflix.comments
Đầu ra:
[
{
name: 'sxkybvzb6',
email: '[email protected]',
date: ISODate('2018-08-14T15:05:03.142Z')
},
{
name: 'jjjdmntww',
email: '[email protected]',
date: ISODate('2018-08-14T15:03:14.306Z')
},
{
name: 'yznjm1yul',
email: '[email protected]',
date: ISODate('2018-08-14T15:01:16.716Z')
},
{
name: 'sg1u6swo4',
email: '[email protected]',
date: ISODate('2018-08-14T15:00:25.211Z')
},
{
name: 'g7pnd0yy2',
email: '[email protected]',
date: ISODate('2018-08-14T14:53:11.550Z')
}
]Đang tải editor...