Я пытаюсь найти окрестности, которые соответствуют моему состоянию - полигон boundries
пересекается с координатами поста, но я не могу этого сделать - не могу использовать let
в моем pipeline $match
пример почтового объекта:
{
_id: ObjectId,
...,
location: {
...,
coordinates: {
type: 'Point',
coordinates: [number, number]
}
}
};
пример объекта соседства:
{
_id: ObjectId,
...,
boundries: {
type: 'Polygon',
coordinates: [ [ [number, number], [number, number], [number, number], [number, number], [number, number] ] ]
}
};
пример запроса, который я пытаюсь исправить:
db.posts.aggregate([
{ $match: { _id: ObjectId('5a562e62100338001218dffa') } },
{
$lookup: {
from: 'neighborhoods',
let: { postCoordinates: '$location.coordinates.coordinates' },
pipeline: [
{
$match: {
boundries: {
$geoIntersects: {
$geometry: {
type: 'Point',
coordinates: '$$postCoordinates'
}
}
}
}
}
],
as: 'neighborhoods'
}
}
]);