Looking for recommendations on ways to standardize 2 different outputs from mongoose / Express where (1) is the doc structure and (2) is the geoNear output below:
I have Mongo structure of data similar to this:
stores [
{
"ID": "0000011237",
"CoName": "Smurfit-Stone Container Canada, L.P.",
"Geo": {
"lon": -79.9053,
"lat": 43.5345
},
"Products": [
{
"Store": "0000011237",
"PID": "NA - M09",
"ComID": "NA - M09"
},
{
"Store": "0000011237",
"PID": "NA - M10",
"ComID": "NA - M10"
}]
}
from Mongoose/Express I get the documents via an API that look exactly as above. However, geospatial queries using geoNear ( i need it for automatic distance calculations ) get put into:
{
"documents": [
{
"ns": "str1.stores",
"near": "0110000101111110010111110000100001110000100010000101",
"results": [
{
"dis": 0.00026746631520032326,
"obj": {
This creates inconsistent structure for the API I'm working on.
Is there any way parse both results from the Mongoose/Mongo into a better organized structure, perhaps similar to that where I have "dis" calculations for each store document?
Any best practices on how to combine these two "views" to the documents, or tutorials on this?
thanks!