2016-08-01 68 views
1

每當我嘗試從集合中返回一些數據時,它將返回一個空數組。我使用的是鐵的路由器,這是我的代碼:

客戶:

Meteor.call('insertEvent', { 
    "eventLoc": { 
     "type" : "Point", 
     "coordinates": [ 
      eventLongitude, 
      eventLatitude 
     ]} 
} 

function getBox() { 
var bounds = GoogleMaps.maps.mapSeek.instance.getBounds(); 
var ne = bounds.getNorthEast(); 
var sw = bounds.getSouthWest(); 
    Session.set('box', [[sw.lat(),sw.lng()],[ne.lat(),ne.lng()]]); 
} 

getbox(); 

服務器:

Meteor.publish('publicPlaces', function(box) { 
var find = { 
    eventLoc: { 
     $geoWithin: { 
      $box: box 
     } 
    } 
}; 

return Events.find(find); 
}); 

路線:

Router.route('/seek', function() { 
    this.render('seek'); 
    Meteor.subscribe('publicPlaces', Session.get('box')); 
}; 

回答

2

我認爲,該錯誤是在您的box值。根據MongoDB手冊,您必須先指定經度,而代碼Session.set('box', [[sw.lat(),sw.lng()],[ne.lat(),ne.lng()]]);似乎相反。

+0

Ofcourse,gah我很生氣,因爲錯過了自己。 謝謝 –