What does .populate("author") do in Mongoose?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "Replaces referenced ObjectId with actual related author document". Khi trường author của schema lưu ObjectId kèm ref tới model tác giả, lời gọi populate với tên trường author làm Mongoose chạy thêm một truy vấn vào collection được tham chiếu và thay giá trị ObjectId trong kết quả bằng nguyên tài liệu tác giả, nên có thể đọc ngay post.author.name; dữ liệu lưu trong cơ sở dữ liệu vẫn chỉ là ObjectId. "Creates new author documents" sai vì populate chỉ đọc, không ghi tài liệu nào. "Sorts authors alphabetically" sai vì sắp xếp là việc của sort(); populate có thể nhận tuỳ chọn sắp xếp cho tài liệu con nhưng tự nó không sắp xếp. "Encrypts author field" sai vì populate không mã hoá dữ liệu; mã hoá trường cần plugin hoặc tính năng mã hoá riêng của MongoDB.
Cùng chương 5
Which of the following are true about the match option in the populate() method? (Choose 2 answers)Có lời giảiCâu hỏiWhich of the following are valid options for the populate() method in Mongoose? (Choose 2 answers)Có lời giảiCâu hỏiWhat are not use cases for Mongoose in Node.js?Có lời giảiCâu hỏiCả 45 câu của chủ đề45 câu