Hello everyone!
I have two collections:
I have Projects
collection like this:
{
name: "string",
_id:"string"
}
And “Points” collection like this:
{
_id: "string",
projectId: "string"
meta: "Object"
globalCoordinates: "Object"
localCoordinates: "Object"
}
All I need is to get an array with coordinate objects in this form:
[
{ easting: .. , northing: ... },
{ easting: .. , northing: ... }
]
At the moment, I got such a pipeline, but it returns an array with object:
[{ points: [
{ easting: .. , northing: ... },
{ easting: .. , northing: ... }]
]}
[
{
'$match': {
'_id': 'c73e7ed5-d9d9-4554-ac1c-f8ccf6da49cd'
}
}, {
'$lookup': {
'from': 'SurveyPoint',
'localField': '_id',
'foreignField': 'projectId',
'as': 'points'
}
}, {
'$project': {
'points': {
'$filter': {
'input': '$points',
'as': 'point',
'cond': '$$point.globalCoordinates'
}
},
'_id': 0
}
}, {
'$project': {
'points': {
'$map': {
'input': '$points',
'as': 'point',
'in': {
'easting': {
'$round': [
'$$point.globalCoordinates.easting', 6
]
},
'northing': {
'$round': [
'$$point.globalCoordinates.northing', 6
]
}
}
}
}
}
}
]