I’m trying to create an aggregation pipeline to intersect some shapes with some others. a simplified pipeline is like this:
[
{
'$match': {
'loc.type': {
'$eq': 'Polygon'
}
}
}, {
'$addFields': {
'cor': [
[
-11.337890625, 56.31653672211301
], [
13.1396484375, 42.8115217450979
]
]
}
}, {
'$match': {
'loc': {
'$geoIntersects': {
'$geometry': {
'type': 'LineString',
'coordinates': '$cor'
}
}
}
}
}
]
At the first step, I selected every polygon shape from a collection, in the next stage added some coordinates to it, and at the end match the polygon with the shape added in stage 2. the problem is in stage 3, I can’t fill the coordinates
field with the cor
field created in stage 2.
the error I get is: GeoJSON coordinates must be an array of coordinates.
another similar problem is this:
[
{
'$match': {
'loc.type': {
'$eq': 'Polygon'
}
}
}, {
'$addFields': {
'myshape': {
'type': 'LineString',
'coordinates': [
[
-11.337890625, 56.31653672211301
], [
13.1396484375, 42.8115217450979
]
]
}
}
}, {
'$match': {
'loc': {
'$geoIntersects': {
'$geometry': '$myshape'
}
}
}
}
]
here in stage 2, I created a complete GeoJson shape (field myshape
). I also can’t use myshape
as the shape for $geometry
. here the error I get is: unknown geo specifier: $geometry: "$myshape"
.
how I can use a field from the current document as value for the fields $geometry
or $geometry.coordinates
?