So I know I can write the following MongoDB function which is able to tell me if a set point is inside another geospatial area. However I can’t seem to use the let
function to be able to use the data from the first $match as that has it’s own geospatial data that I want to use for the query.
Query Match Sample
{
"_id":ObjectId('5f58816115890cf60f3a4d5e')
"location": {
"coordinates": [
115.8621,
-31.9674
],
"type": "Point"
}
}
The Query
[{
$match: {
_id: ObjectId('5f58816115890cf60f3a4d5e')
}
}, {
$lookup: {
from: 'CPM',
'let': {
sD: '$_id'
},
pipeline: [
{
$match: {
geometry: {
$geoIntersects: {
$geometry: {
type: 'Point',
coordinates: [
115.8621,
-31.9674
]
}
}
}
}
}
],
as: 'CPM'
}
}]
And it works fine, however how do I take the location information from “A” Collection to use in the $lookup
pipeline?
I tried:
{
from: "CPM",
let:{'location:'$location'},
pipeline:[{$match:{
geometry: {
$geoIntersects: {
$geometry: {'$$location'}
}
},
}}],
as:'CPM'
}
Thinking it would get the location section of the query from A
collection but it did not.