Which statements correctly describe the use of population in Mongoose queries?
4 phương ánCó giải thíchTrung bình
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 gồm hai ý: "Population is used to join data from multiple collections." và "Population can be done using the populate() method in a query.". Population là cơ chế Mongoose thay một trường lưu ObjectId tham chiếu (khai báo kiểu ObjectId kèm ref tới model khác) bằng chính document được tham chiếu. Ví dụ Post.find().populate('author') trả về bài viết kèm cả đối tượng người dùng thay vì chỉ id; Mongoose thực hiện bằng truy vấn phụ tới collection kia rồi ghép kết quả, nên về tác dụng nó giống phép join dữ liệu giữa nhiều collection. "Population is used to update multiple documents." sai vì populate chỉ đọc và ghép dữ liệu khi truy vấn; cập nhật nhiều document là việc của updateMany(). "Population requires the use of schemas only." sai vì thứ populate cần là một trường tham chiếu và biết model đích; thông tin đó thường đặt trong schema bằng ref, nhưng cũng có thể truyền trực tiếp qua tuỳ chọn model khi gọi populate(), nên không phải cứ có schema là đủ hay chỉ có schema mới làm được.
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