2016-09-21 230 views
1

我目前在我的平均应用程序中使用查询时很困难。平均应用程序 - 不能在我的查找请求中使用查询

详细,我想获得在搜索字段中的数据匹配,输入:

$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) 
}); 
} 

在服务器端,我的代码看起来是这样的:

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

此八方通返回完整的集合。 任何想法?

回答

1

请将您的查询传递给查找函数,如果您传递参数,您的请求将具有一些查询参数。

例如 -

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

感谢

+0

作品!非常感谢! 你有什么想法如何查询嵌套对象?这只适用于第一级参数。 – Pascal

+0

db.messages.find({'ImportCollection.value_1':“[email protected]”}) 我希望你能理解格式。 –