I have an issue that chats is not detecting the type “corodinates/location”. I always get back an array of Objects. I am following the docs to specify a geoPoint.
The resulting structure looks like this (mind the Array after ‘location’!)
For some reason location becomes an array and this seems to fool chats, so that the coordinates are not detected as coordinates/location but as an array:
It should look like this
(Example taken from the airbnb sample data)
How can I get the coordinates detected in charts so that I can make use of them??
Your location data is in GeoJSON format, which is something that Charts is able to deal with directly. However unfortunately we can’t handle arrays of GeoJSON objects, which is what you have. The best solution would be to use $unwind in the query bar to get rid of the array, and then it should detect the location data correctly.
Note that if "location" is an array in the original document (as I suspect it is because you’re using $arrayElemAt to get a single country name from it) then the output will also make it an array.
Can you provide the original document format in source collection as well as document format in myColl that you are outputting to? Both projection and updates will traverse arrays and preserve their “array-ness”…
thanks a lot, next time we meet the dink is on me…
This is a stupid mistake I made. Before I $project I have a $lookup stage where I use as: 'location' this is an array. For whatever reason I used location again in the $project to name the projected Object. So in $project the array is picked up from the $lookup and the aggregation does what it should do.
Simply changing the name of the field fixes my mistake and the $project returns an object instead of an array.
Guess this is a further entry on the “don’t do this” list…