错误:无法识别的运算符:流星js中的$ nearSphere [英] Error: Unrecognized operator: $nearSphere in meteor js

查看:78
本文介绍了错误:无法识别的运算符:流星js中的$ nearSphere的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在流星js中有简单的代码,可以在10公里以内的车库附近找到查询,如果在robomongo中手动运行它,查询在我的mongodb数据库中运行正常,但运行正常,但是当我在路线中运行它时会抛出错误.像这样.

i have simple code in meteor js for find near by garages within 10 Kilometres the query works fine in my mongodb database if run it manually in robomongo it works fine but when i run it in my routes it throws an error. like this.

Error: Unrecognized operator: $nearSphere in meteor jsi

我看到一些博客,他们说您需要为此调用服务器端方法.所以我使用下面的代码来调用服务器端路由.

i see some blogs they said you need to call a server side method for this. so i use below code to call a server side route.

Router.route('/search/:name',
                    {name:'searchlist',
                        data:function(){

                            var searchedParams = this.params.name.split('-');

                            var lat = searchedParams.pop();
                            var lng = searchedParams.pop(1);

                            return {searchValue: Centers.find({ coordinates: { $nearSphere: { $geometry: { type: "Point", coordinates: [lng,lat] }, $maxDistance: 10000 } } })} 
                            }   
                        }, { where: "server" }


                    );

如果有人有想法请帮助.

if anyone have idea please help.

推荐答案

首先,查看Styx答案,并通过消除以下部分使该路由成为客户端路由:

First, look at Styx answer and make the route a client route by eliminating this part:

', { where: "server" }'

现在该路由器可供客户端使用,让我们通过将操作员更改为$ near来解决$ nearSphere问题.使用以下代码:

Now that the router is available to the client, let's fix the $nearSphere issue, by changing the operator to $near. Use the following code:

Centers.find(
  {
    geoloc: {
      $near: {
        $geometry: {
          type: "Point",
          coordinates: [lng, lat]
        }
      }
    }
  }
);

尝试一下,让我知道它是否有效.

Give it a try and let me know if it works.

这篇关于错误:无法识别的运算符:流星js中的$ nearSphere的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆