I have two collections in my mongodb. One collection contains id and location while the other collection contains id and various other information. I am trying to create a route such that we we use app.get for http://localhost:3000/:location , it should find the ids for the searched location and then use those ids to give a json response from the detailed collection.
In the code, I am using just one collection and giving a response from it.But, want to use the id provided in the response to create JSON response from the otherdatabase name Specialty.
app.get('/hospital/:location', (req, res) => {
const city = req.params.location
console.log(city)
Hospital.find({city:city},(err, Hospitals)=>{
if(err){
res.send('error')
next();
}
console.log('Search ho gya hai')
res.json(Hospitals)
})
});
Schema 1
const hospitalschema = new Schema({
placeid: String,
name: String,
city: String,
address: String,
latitude: String,
longitude: String,
phone: {
type:String,
default: 'Phone number not available'
},
rating:{
type:String,
default: 'Not Rated Yet'
}
});
Schema 2
const hospitalspecialityschema = new Schema({
placeid: String,
specialities:{
type:Array,
default:''
}
});
I am trying to the the hospitals with particular speciality and then using the placeids I want to show the collection of Schema 1 as JSON output.