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),∗∗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.
Collection users (dữ liệu mẫu sample_mflix.users) đã được nạp sẵn.
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]' }
]Đang tải editor...