Pascal
Pascal

Reputation: 23

MEAN App - Can't use query in my find request

I'm currently having a hard time on using queries within my MEAN App.

In Detail, I'm trying to get the data matching to the input in a search field:

$scope.searchInput = function(search){
$http({
  method: 'GET',
  url: '/search',
  params: {'licensor.name' : search}
})
.success(
function(success){
       console.log(success)
})
.error(
function(error){
      console.log(error)
});
}

On the server side my code looks like this:

app.get('/search', function(req,res){
    ImportCollection.find(function(err, imports){
        if(err) throw err
        res.json(imports)
    });
});

This allways returns the full collection. Any ideas?

Upvotes: 1

Views: 50

Answers (1)

Nitin Dwivedi
Nitin Dwivedi

Reputation: 26

please pass your query with find function, your request will have some query parameter if you are passing the parameter.

for example -

app.get('/search', function(req,res){
    ImportCollection.find(req.query).exce(function(err, imports){
        if(err) throw err
        res.json(imports)
    });
});

Thanks

Upvotes: 1

Related Questions