how to call a method of server folder from client folder in meteor js -
i new meteorjs , want call query should run on server. write method in server side code, throws error this:
error invoking method 'getcenters': internal server error [500]
i want data collection server side beacause $nearsphere not working client side. below, added code have done till now. have 2 files in different directories.
client side code, in projectname/client/templates/pages/search.js
:
template.searchlist.onrendered(function(){ this.searchedstring = router.current().params.name; meteor.call('getcenters',this.searchedstring); });
server side code, in myproject/server/main.js
:
import { meteor } 'meteor/meteor'; meteor.startup(() => { meteor.methods({ 'getcenters': function(searchedparams) { searchedparams = searchedparams.split('-'); var lat = searchedparams.pop(); var lng = searchedparams.pop(1); console.log(centers.find({ coordinates: { $nearsphere: { $geometry: { type: "point", coordinates: [lng, lat] }, $maxdistance: 10000 } } })); } }); });
it seems define methods in meteor.startup of main.js.
you shouldn't that. create separated file in server folder put methods in. main.js should empty except import { meteor } 'meteor/meteor';
another point : meteor.methods console.log
shown in server console. won't see result in browser console.
you don't have callback in client-side call there no result in client...
Comments
Post a Comment