在()。circle()和$ near中的Mongoose给Mongo Query带来了明显的结果

时间:2016-10-01 22:38:24

标签: node.js mongodb mongoose geospatial

我有一个Node.js测试,其中有多个对象模拟从一个地图中的某个点移开而且我会在这个点上进行测试。 每个对象对应一个带有嵌套遗留2d索引'location.loc'的模型。

我使用了这个查询

var center={_lat:20,lng:-100};

var area = { 
      center: [center._lng,center._lat], 
      radius: 100,//This are supossed to be meters
      unique: true,
      spherical: true }


  MyModel.where('location.loc')
         .within()
         .circle(area)
         .exec(function (err, records) {
            if (err) { 
              throw err; 
            }
            //Log Length of records
         });

  MyModel.find({  
    "location.loc": {
      $near: [center._lng,center._lat],
      $maxDistance: 1 //This is suposed to be a mile
    }
    }).exec(function(err, documents) {
        if (err) { 
          throw err; 
        }
        //Log documents length
    });

但是这两个脚本都会返回我的整个文档集,即使它们离这一点很远。 同时我在我的Mongo客户端使用$ near,$ geoWithin和那些查询进行相同的查询,这给了我正确的答案。

我的Mongoose脚本出了什么问题?

对于这种情况,只应该使用内部()。circle()吗?

1 个答案:

答案 0 :(得分:1)

证明第一个代码中的半径是错误定义的。 在此Mongo documentation中说

  

使用sphere:true,如果指定GeoJSON点,MongoDB使用米作为度量单位

但这是针对GeoJSON点和from bs4 import BeautifulSoup import urllib import pandas as pd from difflib import SequenceMatcher as SM def maxmatching_algo2(data, counter): data_word=[] data_word=str(data).split(" ") k=[] for i in processsorList_global: k+=str(i).split(",") temp=0 rank_list=[] while temp<len(k): t=[] t+=str(k[temp]).split(" ") union_set=set(t)&set(data_word) rank_list+= [len(union_set)] temp+=1 index= rank_list.index(max(rank_list)) if index==0: df1.ix[counter, cl]="na" else: df1.ix[counter, cl]=index def processor_list_online(): processsorList = [] url = "http://www.notebookcheck.net/Smartphone-Processors-Benchmark-List.149513.0.html" htmlfile = urllib.urlopen(url) soup = BeautifulSoup(htmlfile, 'html.parser') count = 1 temp_count=0 x=str() while True: if x=="Qualcomm Snapdragon S1 MSM7227": break else: for i in soup.find_all('tr'): count+=1 temp=0 for j in i.find_all('td', attrs={'class': 'specs'}): if temp==1: processsorList += [j.text] x=j.text temp+=1 temp_count+=1 print temp_count return processsorList ############################################################################################################################### ############################################################################################################################### df1 = pd.read_csv('proddata2.csv') x = list(df1.columns.values) ####################### name of column cl = len(x) ####################### column Length rl = len(df1.index) ####################### row length df1["Processor Rank"] = "" counter = 0 count = [] processsorList_global = processor_list_online() for i in processsorList_global: print i counter=0 while counter < cl: if x[counter] == "processor_type": count = counter break counter += 1 counter = 0 data = [] while counter < rl: data = df1.ix[counter, count] #print data if data=="na": df1.ix[counter, cl]="na" else: # maxmatching_algo(data, counter) maxmatching_algo2(data, counter) counter +=1 #print df1 #df1.to_csv('final_processor_rank.csv', sep=',') print "process completed" 对于遗留坐标格式[long,lat],我们必须将半径值以英里为单位除以3963.2以将其转换为弧度。请参阅此Example