我有一个如下集合:
Schema.Place = new SimpleSchema({
type: {
type: String,
autoValue: function(){ return 'Point'; }
},
coordinates: {
type: [Number],
decimal:true,
},
});
Schema.Direction = new SimpleSchema({
_id: {
type: String,
optional: true,
},
from: {
type: Schema.Place,
},
to: {
type: Schema.Place,
}
});
然后,我想根据从和到点查询相同的路线。第一个问题是我无法在同一个查询中查询两个地理索引,所以我按照以下方式执行:
Meteor.publish('Directions', function(direction){
var ids = Ride.find({
active: true,
from: {
$near: {
$geometry: {
type: 'Point',
coordinates: direction.from.coordinates,
},
$maxDistance: 5000,
}
}
}).map(function(item){return item._id});
return Ride.find({
_id: {$in: ids},
to :{
$near: {
$geometry: {
type: 'Point',
coordinates: direction.to.coordinates,
},
$maxDistance: 5000,
}
}
});
});
问题在于,由于双重查询过滤,发布会失去其反应性......
我有一些想法如何完成这项工作但对我来说似乎很奇怪没有更好的方法: