猫鼬中的选择和填充功能不起作用



我正在尝试获取带有电影标题的Movie字段,并填充流派集合。但我得到的回应是拥有所有财产的电影收藏。

const movies = await Movie.find()
.populate("genre", "name")
.sort("name")
.select("title");

响应我收到

[{&quot_id":"623724b0bdb7598002f04b83";,"标题":"泰坦尼克号";,"numberInStock":10,"dailyRentalRate":5."流派":{&quot_id":"61e923f6860764ef514a64b5";,"name":"浪漫";,&quot__v":0}},{&quot_id":"623724d6bdb7598002f04b85〃;,"标题":"哈利波特";,"numberInStock":15,"dailyRentalRate":5."流派":{&quot_id":"61e923da860764ef514a64aa";,"name":"动作";,&quot__v":0}}]

您可以在select字段前面使用(-(号。例如:

const movies = await Movie.find()
.populate("genre", "name")
.sort("name")
.select("title -numberInStock -dailyRentalRate");

您可以按照以下更新查询

const-movies=等待Movie.find((.填充({path:"name",select:"title"}(

最新更新