'Select and Populate function in mongoose is not working

I am trying to get the Movie field with movie title and populating the genre collection. But the response I am getting is the movies collection with all properties.

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

Response I got

[ { "_id": "623724b0bdb7598002f04b83", "title": "Titanic", "numberInStock": 10, "dailyRentalRate": 5, "genre": { "_id": "61e923f6860764ef514a64b5", "name": "romantic", "__v": 0 } }, { "_id": "623724d6bdb7598002f04b85", "title": "Harry Potter", "numberInStock": 15, "dailyRentalRate": 5, "genre": { "_id": "61e923da860764ef514a64aa", "name": "action", "__v": 0 } } ]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source