Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Meteor.methods and Meteor.call

I have the following server code:

Meteor.startup(function () {
  Meteor.publish("AllMessages", function() {
    lists._ensureIndex( { location : "2d" } );
    return lists.find();
  });
});

Meteor.methods({
  getListsWithinBounds: function(bounds) {
    lists._ensureIndex( { location : "2d" } );
    return lists.find( { "location": { "$within": { "$box": [ [bounds.bottomLeftLng, bounds.bottomLeftLat] , [bounds.topRightLng, bounds.topRightLat] ] } } } );
  }
});

and this client code:

Meteor.startup(function () {
  map = L.map('map_canvas').locate({setView: true, maxZoom: 21});
  L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
      attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  }).addTo(map);
    bounds = {};    
    map.on('locationfound', function(e){ 
      bounds.bottomLeftLat = map.getBounds()._southWest.lat;
      bounds.bottomLeftLng = map.getBounds()._southWest.lng;
      bounds.topRightLat = map.getBounds()._northEast.lat;
      bounds.topRightLng = map.getBounds()._northEast.lng;
      console.log(bounds);
      Meteor.call("getListsWithinBounds", bounds, function(err, result) {
        console.log('call'+result); // should log a LocalCursor pointing to the relevant lists
      });
    });
});

I get on my server logs:

Internal exception while processing message { msg: 'method',
  method: 'getListsWithinBounds',
  params: 
   [ { bottomLeftLat: 50.05008477838258,
       bottomLeftLng: 0.384521484375,
       topRightLat: 51.63847621195153,
       topRightLng: 8.3221435546875 } ],
  id: '2' } undefined

but I cant't figure out why...

like image 797
George Katsanos Avatar asked Mar 22 '13 21:03

George Katsanos


People also ask

What is Meteor methods?

Meteor methods are functions that are written on the server side, but can be called from the client side. On the server side, we will create two simple methods. The first one will add 5 to our argument, while the second one will add 10.

What is Meteor call?

Meteor. call() is typically used to call server-side methods from the client-side. However, you can also use Meteor. call() on the server-side to call another server-side function, though this is not recommended.

What is Meteor API?

Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node. js and general JavaScript community.


1 Answers

You cannot return a Collection cursor - it's unable to be converted into an EJSON object. Return the results of your query as an array.

e.g.

return Lists.find(...).fetch();
like image 97
cazgp Avatar answered Sep 19 '22 21:09

cazgp