我正在尝试获取带有电影标题的Movie字段,并填充流派集合。但我得到的回应是拥有所有财产的电影收藏。
const movies = await Movie.find()
.populate("genre", "name")
.sort("name")
.select("title");
响应我收到
[{"_id":"623724b0bdb7598002f04b83";,"标题":"泰坦尼克号";,"numberInStock":10,"dailyRentalRate":5."流派":{"_id":"61e923f6860764ef514a64b5";,"name":"浪漫";,"__v":0}},{"_id":"623724d6bdb7598002f04b85〃;,"标题":"哈利波特";,"numberInStock":15,"dailyRentalRate":5."流派":{"_id":"61e923da860764ef514a64aa";,"name":"动作";,"__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"}(