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: 10 user có tên hiển thị

    Lấy 10 user đầu tiên theo _id tăng dần và chỉ in ra name, email (không hiển thị _id). Pipeline gồm 3 bước theo thứ tự: sort∗∗(theo‘id‘ta˘ngda^ˋn),∗∗sort** (theo `_id` tăng dần), **sort∗∗(theo‘i​d‘ta˘ngda^ˋn),∗∗project và $limit.

    Chương trình chỉ được in kết quả của một câu aggregate này. Không cần lệnh use.

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

      Collection users (dữ liệu mẫu sample_mflix.users) đã được nạp sẵn.

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

      Kết quả của câu aggregate theo định dạng mongosh: một mảng 10 document { name: ..., email: ... }. Ví dụ dòng đầu:

      [
        { name: 'Ned Stark', email: '[email protected]' },
        ...
      ]
      

    Ví dụ:

    Đầu vào:

    sample_mflix.users

    Đầu ra:

    [
      { name: 'Ned Stark', email: '[email protected]' },
      { name: 'Robert Baratheon', email: '[email protected]' },
      {
        name: 'Jaime Lannister',
        email: '[email protected]'
      },
      { name: 'Catelyn Stark', email: '[email protected]' },
      { name: 'Cersei Lannister', email: '[email protected]' },
      { name: 'Daenerys Targaryen', email: '[email protected]' },
      { name: 'Jorah Mormont', email: '[email protected]' },
      { name: 'Petyr Baelish', email: '[email protected]' },
      { name: 'Viserys Targaryen', email: '[email protected]' },
      { name: 'Jon Snow', email: '[email protected]' }
    ]

    Chủ đề

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

    Đang tải editor...