db.command.geoWithin
需对查询字段建立地理位置索引
找出字段值在指定区域内的记录,无排序。指定的区域必须是多边形(Polygon)或多边形集合(MultiPolygon)。
方法签名:
function geoWithin(IOptions): Command
interface IOptions {
geometry: Polygon | MultiPolygon // 地理位置
}
示例代码
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const _ = db.command
const {Point, LineString, Polygon} = db.Geo
exports.main = async (event, context) => await db.collection('restaurants').where({
location: _.geoWithin({
geometry: Polygon([
LineString([
Point(0, 0),
Point(3, 2),
Point(2, 3),
Point(0, 0)
])
]),
})
})