【问题标题】:Loopback MongoDB GeoIp 'near' query from angular client来自角度客户端的环回 MongoDB GeoIp 'near' 查询
【发布时间】:2017-04-25 15:35:05
【问题描述】:

我正在使用一个环回角度项目,将 mongoDB 作为数据库。在环回 mongoDB 查询中按纬度和经度搜索最近的用户,使用 'near' 关键字导致错误。

注意:我在 2d 中索引了 'loc' 字段。

错误:

> D:\nodejs\your-time\version_1\node_modules\mongodb\lib\utils.js:98
    process.nextTick(function() { throw err; });
                                  ^
Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11)
    at ServerResponse.header (D:\nodejs\your-time\version_1\node_modules\express
\lib\response.js:719:10)
    at HttpContext.done (D:\nodejs\your-time\version_1\node_modules\strong-remot
ing\lib\http-context.js:651:9)
    at D:\nodejs\your-time\version_1\node_modules\strong-remoting\lib\rest-adapt
er.js:492:11
    at D:\nodejs\your-time\version_1\node_modules\strong-remoting\node_modules\a
sync\lib\async.js:251:17
    at D:\nodejs\your-time\version_1\node_modules\strong-remoting\node_modules\a
sync\lib\async.js:154:25
    at D:\nodejs\your-time\version_1\node_modules\strong-remoting\node_modules\a
sync\lib\async.js:248:21
    at D:\nodejs\your-time\version_1\node_modules\strong-remoting\node_modules\a
sync\lib\async.js:612:34
    at interceptInvocationErrors (D:\nodejs\your-time\version_1\node_modules\str
ong-remoting\lib\remote-objects.js:690:22)
    at D:\nodejs\your-time\version_1\node_modules\loopback-phase\node_modules\as
ync\lib\async.js:154:25

我的代码如下:

Profile.find({
    filter: {
        where: {
            type: 'expert',
            is_verified: 1,
            expert_category: $scope.expertCategory,
            loc: {
                'near': [lat, lng]
            }
        }
    }
}).$promise.then(function(users) {
    console.log(users);
    $scope.users = users;
});

我做错了什么?

【问题讨论】:

  • 看起来问题是别的,你试过删除loc: { 'near': [lat, lng]}吗?确保它在没有纬度/经度参数的情况下工作。
  • 试试{where: {geo: {near: {lat: 42.266271, lng: -72.6700016} }}} - 用JS对象代替数组。
  • 我试过了,同样的问题。我发现环回仅支持 2dsphere 上的地理查询(我在 2d 中编制索引)现在显示一个新错误,如上所示。
  • 嘿 @jaym ,将位置字段类型从 geopint 更改为 object 现在解决了这个问题,谢谢。
  • 如果您解决了自己的问题,请提供答案并将其标记为已接受。 (如果可以进一步激励您,您将获得徽章)

标签: angularjs node.js express mongoose loopbackjs


【解决方案1】:

我刚刚从以下链接发现环回仅支持 2dsphere 上的地理查询(我在 2d 中编制索引): Loopback: near filter on object sub-field

现在在 2dsphere 中建立索引并将位置字段类型更改为对象后,问题就解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 2014-03-06
    • 1970-01-01
    相关资源
    最近更新 更多