I've been working with mongoDB in node using mongoose. The following query to mongoose is made when a GET request is made to a route (e.g. localhost:7000/restaurants) and displays an array full of matching objects
async func() {
return this.Restaurants.find({$or: [{city: somecity}, {postal_code: somepostalcode}]}).then(result => {
return result;
})
}
I tried a similar thing using postgres, however, calling it returns nothing on the browser, but is successfully logged onto the console:
async func(){
return await client.query(`SELECT * FROM restaurants WHERE city = '${somecity}' OR postal_code = '${somepostalcode}';`, (err, res) => {
console.log(res.rows);
return res.rows;
})
}
Why does this happen, if they both seem to return the same type of object? Is there a way to make the postgres result visible?
Thank you for the help!
SELECT * FROM restaurants WHERE city = '${somecity}' OR postal_code = '${somepostalcode}';Or follow their guide client.query(<query>,<value>,<callback>)