2013-03-22 19 views
7

Tôi có mã máy chủ sau:Sử dụng Meteor.methods và 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] ] } } }); 
    } 
}); 

và mã này khách hàng:

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

tôi nhận được trên các bản ghi máy chủ của tôi:

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 

nhưng tôi không thể tìm ra lý do tại sao ...

+0

Bạn có thể kiểm tra thiết bị đầu cuối sao băng của mình cùng một lúc điều này xảy ra không? – Akshat

+0

Thông báo lỗi ở phía dưới là thiết bị đầu cuối thiên thạch .. –

+0

Bạn đã lập chỉ mục các trường cho truy vấn không gian địa lý chưa? Meteor có thể ẩn các lỗi mongodb – Akshat

Trả lời

16

Bạn không thể trả về con trỏ Bộ sưu tập - nó không thể được chuyển đổi thành đối tượng EJSON. Trả về kết quả truy vấn của bạn dưới dạng một mảng.

ví dụ:

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

Đúng, nhưng đó không phải là nguồn dữ liệu phản ứng. Có lẽ bạn nên sử dụng 'Meteor.publish' thay vì' Meteor.methods' trong trường hợp này? ... –

Các vấn đề liên quan