1

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?

j0e
  • 1,441
  • 1
  • 15
  • 17
  • 1
    AFAIK, `minimongo doesn't support all the methods which supports in server side, just check all the methods like $near,$geometry and $maxdistance are supported in minimongo – Sasikanth May 25 '15 at 01:58
  • i've also bumped into a similar problem, i think there is no way to do it. my one hope is that there's a way to return the actual distance back from the query and use it. am i correct that the code above does not return a distance value? – Randy L Jun 21 '15 at 21:46

1 Answers1

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?

Guy
  • 65,082
  • 97
  • 254
  • 325
  • This line is probably useless. But as it is a conditional expression without any side effect, it can't cause harm AFAIK. – Sylvain Leroux May 24 '15 at 21:59
  • @SylvainLeroux I agree that it can't cause harm. Just questioning if it was supposed to do something and by not doing something is what's causing the problem... – Guy May 24 '15 at 22:03
  • Yeah, good eye Guy. This conditional is useless and has been removed from the mix. It doesn't change anything though. – j0e May 24 '15 at 22:26