I'm using Meteor to return a list of Venues that are closest to the user's geolocation. I have the sort happening correctly from the server but the data is a little jumbled by the time it hits the client. It's my understanding that another sort needs to happen on the client once the data is received.
I have the following code in publish.js on the server:
Meteor.publish('nearestVenues', function(params){
var limit = !!params ? params.limit : 50;
if (!!params && !!params.coordinates){
return Venues.find(
{ 'location.coordinates':
{ $near :
{ $geometry :
{ type : "Point" ,
coordinates : params.coordinates
},
$maxDistance : 6000,
spherical: true
}
}
}, {limit: limit});
} else {
return Venues.find({}, {limit: limit});
}
});
And the following in a template helper for my view which returns nothing:
Template.VenueList.helpers({
venues: function(){
return Venues.find(
{ 'location.coordinates':
{ $near :
{ $geometry :
{ type : "Point" ,
coordinates : Session.get('currentUserCoords')
},
$maxDistance : 6000,
spherical: true
}
}
}, {limit: 10})
// return Venues.find({}, {limit: 5, sort: {_id: -1, createdAt: -1}});
}
EDIT: Removed extraneous params ? !!params : 50;
code from beginning of publish statement.
Note: the commented out code at the bottom of the helper does in fact work so I know this is the correct place to do a client-side sort. So, how do I do a client side sort when the information is sorted by a Mongo geospatial method? There has to be a way to sort geolocation data from closest to farthest from a location— what am I missing here?
答案 0 :(得分:0)
This might be a red herring but I notice that the third line in your first code snippet doesn't seem to do anything:
params ? !!params : 50;
What is that line supposed to do? Perhaps if that is fixed that will solve the problem?