【问题标题】:MEAN App - Can't use query in my find requestMEAN App - 无法在我的查找请求中使用查询
【发布时间】:2017-01-29 08:10:27
【问题描述】:

我目前很难在 MEAN 应用中使用查询。

详细来说,我正在尝试获取与搜索字段中的输入匹配的数据:

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

这总是返回完整的集合。 有什么想法吗?

【问题讨论】:

    标签: javascript rest express mean-stack meanjs


    【解决方案1】:

    请使用 find 函数传递您的查询,如果您传递参数,您的请求将包含一些查询参数。

    例如——

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

    谢谢

    【讨论】:

    • 有效!非常感谢!您对如何查询嵌套对象有任何想法吗?这仅适用于一级参数。
    • db.messages.find( { 'ImportCollection.value_1': "reservations@marriott.com" } ) 希望你理解格式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 2017-11-30
    • 2017-04-24
    • 2021-01-10
    • 2021-07-09
    • 2017-10-18
    相关资源
    最近更新 更多