Can anyone help me with this, if i run this query:
db.getCollection(‘users’).aggregate([
{ $unwind: ‘$addresses’ },
{ $project: { coordinates: [ ‘$addresses.region.longitude’, ‘$addresses.region.latitude’ ] } },
])
I get this results:
/* 1 */
{
"_id" : ObjectId("6197a78308591026b742cbc7"),
"coordinates" : [
-8.88180350512795,
38.5628716186268
]
}
/* 2 */
{
"_id" : ObjectId("6199798916317b0c2dcab874"),
"coordinates" : [
-9.15904389999993,
38.7235087
]
}
/* 3 */
{
"_id" : ObjectId("6199798916317b0c2dcab874"),
"coordinates" : [
-8.6923178,
41.1846394
]
}
Then if i add a lookup with a pipeline:
db.getCollection('users').aggregate([
{ $unwind: '$addresses' },
{ $project: { coordinates: [ '$addresses.region.longitude', '$addresses.region.latitude' ] } },
{
$lookup: {
from: 'deliveryareas',
let: { userCoordinates: '$coordinates' },
pipeline: [
{ $match: {
area: {
$geoIntersects: {
$geometry: {
type: 'Point',
coordinates: '$userCoordinates',
},
},
}
} },
],
as: 'inRegion',
},
},
])
I get the error: i have the error: Point must be an array or object!
But if i replace the variable $$userCoordinates by a fixed value, for example [ -8.88180350512795, 38.5628716186268 ] (that i have on the users) the query run with success.