在 Sails 中使用 MongoDB 的地理空间功能
Using MongoDB's Geospatial features in Sails
我想知道是否可以在 Sails and Waterline 中使用 MongoDb 的地理特征。
基本上,我需要查询 属性 范围内的列表,例如某个位置 [x, y] 的 5 公里半径范围内
使用 Mongoose,我将执行以下操作:
var area = { center: [5.23, 1.9], radius: 5, unique: true, spherical: true };
var query = Property.find();
query
.where('location')
.within()
.circle(area)
.populate('owner', 'name image')
.execAsync()
.then(function (listings){
// respond
}
其中 location 是带经度和纬度的类型数组。
我怎样才能在吃水线上做到这一点。如果不可能,有哪些可用选项。我已经看到有些人已经能够禁用水线并使用 mongoose 或其他 orms,但这似乎很老套,而且我认为你可能会失去帆的蓝图功能。也许小径?更改 orms 似乎是内置的。
水线是不可能的,但你总是可以使用.native查询:https://github.com/balderdashy/sails-docs/blob/master/reference/waterline/models/native.md
我想知道是否可以在 Sails and Waterline 中使用 MongoDb 的地理特征。
基本上,我需要查询 属性 范围内的列表,例如某个位置 [x, y] 的 5 公里半径范围内 使用 Mongoose,我将执行以下操作:
var area = { center: [5.23, 1.9], radius: 5, unique: true, spherical: true };
var query = Property.find();
query
.where('location')
.within()
.circle(area)
.populate('owner', 'name image')
.execAsync()
.then(function (listings){
// respond
}
其中 location 是带经度和纬度的类型数组。
我怎样才能在吃水线上做到这一点。如果不可能,有哪些可用选项。我已经看到有些人已经能够禁用水线并使用 mongoose 或其他 orms,但这似乎很老套,而且我认为你可能会失去帆的蓝图功能。也许小径?更改 orms 似乎是内置的。
水线是不可能的,但你总是可以使用.native查询:https://github.com/balderdashy/sails-docs/blob/master/reference/waterline/models/native.md