2013-03-22 7 views
7

मैं निम्न सर्वर कोड है:का उपयोग Meteor.methods और Meteor.call

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] ] } } }); 
    } 
}); 

और इस ग्राहक कोड:

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 
     }); 
    }); 
}); 

मेरी सर्वर लॉग पर मैं:

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 

लेकिन मैं यह नहीं समझ सकता कि क्यों ...

+0

क्या आप एक ही समय में अपने उल्का टर्मिनल की जांच कर सकते हैं? – Akshat

+0

नीचे दिए गए त्रुटि संदेश उल्का टर्मिनल है .. –

+0

क्या आपने भूगर्भीय क्वेरी के लिए फ़ील्ड अनुक्रमित किए हैं? उल्का mongodb त्रुटियों को छिपा सकता है – Akshat

उत्तर

16

आप एक संग्रह कर्सर वापस नहीं कर सकते - यह एक ईजेएसओएन ऑब्जेक्ट में परिवर्तित करने में असमर्थ है। एक सरणी के रूप में अपनी क्वेरी के परिणाम लौटें।

उदा।

return Lists.find(...).fetch(); 
+1

ठीक है, लेकिन यह एक प्रतिक्रियाशील डेटा स्रोत नहीं होगा। हो सकता है कि आप इस मामले में 'Meteor.methods' के बजाय 'Meteor.publish' का उपयोग करके बेहतर हो जाएंगे? ... –

संबंधित मुद्दे