Các lượt nộp
    Danh sách bài
    Trang chủ
    Báo lỗi
    solution
    Đăng nhập
    Đăng nhập

    Đề bài: 5 comment mới nhất

    Trong collection comments, sắp xếp comment theo date giảm dần, lấy 5 comment mới nhất. Pipeline: sort+sort + 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.

    • Định dạng đầu vào:

      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.

    • Định dạng đầu ra:

      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') }
    ]

    Chủ đề

    🗄️ Cơ sở dữ liệuMongodbAggregationTất cả môn học

    Đang tải editor...