Reputation: 1
I'm creating a react app and I connected my backend mongo where I want to store all my car brands, year, models etc. In react I'm using the select tag and there I get everything that is in the db. DB running. However, whenever I press a specific car brand and try to pick the year with another select tag it shows me the years of all the other car brands. How can I do it so it only shows me years of that specific car brand? Should only show 2012.
My get function
carRoutes.route('/').get(function(req, res) {
Car.find(function(err, car) {
if(err) {
console.log(err);
} else{
res.json(car);
}
}).collation().sort({car_description:1});
});
My Schema
let Car = new Schema({
car_description: {
type: String
},
car_year:{
type: String
}
});
Upvotes: 0
Views: 451
Reputation: 1985
Try something like this (assuming car_description means the name):
Car.find({car_description: 'Audi'}).select('car_year -_id');
// you can replace 'Audi' with a variable which is assigned with the selected car name
Upvotes: 1