来自 angular 客户端的环回 MongoDB GeoIp 'near' 查询

Loopback MongoDB GeoIp 'near' query from angular client

我正在使用环回 angular 项目,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;
});

我做错了什么?

我刚刚从以下 link 中发现 loopback 仅支持 2dsphere 上的地理查询(我在 2d 中索引):

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