# db.command.geoWithin

To set up a geographical location index for the queried field

Finds out the records in which the value of a field is within the specified area and displays the records without sorting. The specified area should be Polygon or MultiPolygon.

Method signature:

function geoWithin(IOptions): Command

interface IOptions {
  geometry: Polygon | MultiPolygon // Geographical location
}

Sample code

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) => {
  return await db.collection('restaurants').where({
    location: _.geoWithin({
      geometry: Polygon([
        LineString([
          Point(0, 0),
          Point(3, 2),
          Point(2, 3),
          Point(0, 0)
        ])
      ]),
    })
  })
}
点击咨询小助手