我有一个模式,看起来像这样:
var UserSchema = new Schema({
name: {type : String, required: true},
location_a: {type: [Number], default: [0,0], index: '2dsphere'},
location_b: {type: [Number], default: [0,0], index: '2dsphere'}
});我的搜索输入有位置和距离。现在,我想让拥有location_a或location_b的用户接近搜索的位置。
我尝试了一个类似如下的查询:
query = query.and([
{ $or: [
query.where('location_a').near({
center: {type: 'Point', coordinates: [long, lat]},
maxDistance: distance * 1000, spherical: true
}),
query.where('location_b').near({
center: {type: 'Point', coordinates: [long, lat]},
maxDistance: 100 * 1000, spherical: true
})
]}
]);但它使我的应用程序崩溃:"RangeError:超过最大调用堆栈大小“
发布于 2016-08-05 17:50:46
我在查询中使用了错误的格式。这就是你怎么做的。
query = query.and([
{ $or: [
{
"at_student_location": {
"$near": [12.5386, 41.884],
"$maxDistance": 1000
}
}
,
{
"at_home_location": {
"$near": [12.5386, 41.884],
"$maxDistance": 1000
}
}
]}
]);问题是mongo在每个查询中只接受一个geoNear表达式,所以不可能做到这一点。
https://stackoverflow.com/questions/38785466
复制相似问题