I am using loopback to serve the API for my application and I tried to change the GET request for some data.
As of now the query fetches all the results for a particular API:
People.find({
where: {
'town': 'name of a town'
}
}).$promise
// Promise is fulfilled and people returned
.then(function(results) {
$scope.people = results;
})
// Promise is rejected and error catched
.catch(function(err) {
$scope.errors.PeopleFind = JSON.stringify(err.data.error.message ?
err.data.error.message :
err.data.error.errmsg
);
});
I already tried with adding single quotes to the where clause or to do something like .find({ where : { town : 'name of a town' }}.
No matter where I put the quotes the results are always the whole package. How would I query for just the results that I'm interested in?
Thanks in advance
I found the answer thanks to a collegue, I'll write here the answer
People .find({ filter: { where: {Town : currentUserTown} } })
The documentation for the loopback framework did not state that you needed to apply a filter object to actually filter the results, in fact you can check the documentation with this example they wrote:
Cars.find({where: {carClass:'fullsize'}});
Before the where clause object you need to write the filter object that contains the clause, that should solve the problem with the query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With