2016-09-21 231 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]」}) 我希望你能理解格式。 –