gpt4 book ai didi

javascript - 使用 Meteor.methods 和 Meteor.call

转载 作者:数据小太阳 更新时间:2023-10-29 04:27:50 25 4
gpt4 key购买 nike

我有以下服务器代码:

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

但我想不通为什么...

最佳答案

你不能返回一个 Collection 游标——它不能被转换成一个 EJSON 对象。将查询结果作为数组返回。

例如

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

关于javascript - 使用 Meteor.methods 和 Meteor.call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15579891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com