# db.command.geoIntersects

To set up a geographical location index for the queried field

Finds out the records in which the given geographical location graph is intersected

Method signature:

function geoIntersects(IOptions): Command

interface IOptions {
  geometry: Point | LineString | MultiPoint | MultiLineString | Polygon | MultiPolygon // Geographical location
}

Sample code: Find out the records in which the geographical location graph intersects a polygon.

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: _.geoIntersects({
      geometry: Polygon([
        LineString([
          Point(0, 0),
          Point(3, 2),
          Point(2, 3),
          Point(0, 0)
        ])
      ]),
    })
  })
}
点击咨询小助手