I am trying to create an app that will limit places by a lat long in meteor. For some reason when I run the subscription I always get all the data return regardless of the $maxDistance I have set.
Here is some sample code of what I am doing:
test.coffee:
@Places = new Mongo.Collection 'Places'
if Meteor.isClient
Meteor.subscribe('Places', {lat: 47.5105794, lng: -122.19099059999999})
Template.closePlaces.helpers
closePlaceData: () -> Places.find().fetch()
if Meteor.isServer
Places.find().count() is 0
Places.insert
type: 'beauty'
name: 'Salona Del Rey'
address: '1234 Fake Street, Seattle, WA 98001'
loc: {
type: "Point"
coordinates: [-122.2222,47.4700]
}
phone: '206-555-1212'
operates: [{day:"Monday", start:"8", close:"22"},{day:"Tuesday", start:"8", close:"22"},{day:"Wednesday", start:"8", close:"22"},{day:"Thursday", start:"8", close:"22"},{day:"Friday", start:"8", close:"22"},{day:"Saturday", start:"10", close:"20"},{day:"Sunday", start:"12", close:"16"}]
offers: ['0001', '0002', '0003', '0005'] `
Places._ensureIndex({'loc ':'2dsphere'})
Meteor.publish 'Places', (latLng) ->
statement = {loc: {$near: { $geometry: { type: "Point", coordinates: [ latLng.lng , latLng.lat ]},$maxDistance: 10 }}}
Places.find(statement)
test.html
<body>
{{> closePlaces}}
</body>
<template name='closePlaces'>
<ul class='places-list'>
{{#each closePlaceData}}
{{> closePlace}}
{{/each}}
</ul>
</template>
<template name='closePlace'>
<div>{{ name }} <div class='button place'>More info ></div></div>
</template>
This subscription should only return something if the MaxDistance is set to 10,000. The way it is set right here (to 10) should not return anything.
Been banging my head against this one for a while and any help would be appreciated! Thanks.