how to Suppress value data types in MongoDB Stitch http get function

29 views
Skip to first unread message

Mahesh Maheswaran

unread,
Jun 23, 2019, 7:50:47 AM6/23/19
to MongoDB Stitch Users
Hello Experts,

I have created a http get service to show all data from one collection. But json is returning data type also . Bu I don't want to show data types.

const result =  doc.find({}).toArray();
return result;

Drew DiPalma

unread,
Jun 23, 2019, 10:24:53 AM6/23/19
to MongoDB Stitch Users
Hi Mahesh – Values are returned in EJSON by default, in order to return as JSON, you can wrap result in JSON.stringify().  

Mahesh Maheswaran

unread,
Jun 24, 2019, 8:30:07 AM6/24/19
to MongoDB Stitch Users
Hello Drew, 

Thanks for your reply. I tried that but when I am wrapping, it is returning as null else it is returning with datatypes.
mongoreturn.PNG

Jose Luis Campos

unread,
Aug 8, 2019, 1:17:59 PM8/8/19
to MongoDB Stitch Users
Hi everybody,

I'm glad to see I'm not the only one trying to load GeoJson to the client directly from Webhook service. that would be great!

I have correctly load to google map API (map.data.loadGeoJson('https://webhooks.mongodb-stitch.com/api/client/v2.0/app/.....) writting 'manually' on function editor like this....

-------------

exports = function(request, response) {
  
    var data = {
      "type": "FeatureCollection",
      "features": [ {"type":"Feature",
                           "geometry":{
                              "type":"Point",
                              "coordinates":[1.4257787262069996,38.92189438027659]
                            }
                          },
                          ...
                         ]
    };
    
    response.addHeader("Content-Type", "application/json");
    response.setBody(JSON.stringify(data));
};

-----------

And works perfectly but..... 

If I try to get the features array from the mongodb context, I cannot get correctly stringify the EJSON from the query result....


Any ideas????

Thanks in advance

Jose Luis Campos
Reply all
Reply to author
Forward
0 new messages