question

ralph avatar image
ralph asked

Anyone have any example code on using mLab or MongoDB Atlas with CloudScript?

I need to use MongoDB as an external database--I figure I'll access mLab or MongoDB Atlas with CloudScript. But PlayFab's documentation and example code in most departments is extremely lacking. Does anyone have a quick example of how to access mLab's REST API via CloudScript?

I've made a few attempts myself, by looking at conventional JavaScript examples to no avail. I'm especially looking at how to pass the authentication header parameters to the REST API.

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

The makeHTTPRequest handler in the basic Cloud Script that is loaded as revision 1 on all new titles is the main thing I'd point to - it shows making an external Web API call to a third party.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ralph avatar image ralph commented ·

@Brendan I'm specifically looking how to call this API with your makeHTTPRequest handler:

https://docs.atlas.mongodb.com/api/#http-methods

I'm having trouble trying to create the proper authentication info in the header. Any help would be greatly appreciated.

mLab seems much more straightforward as you just put your API key on the end of all requests.

0 Likes 0 ·
brendan avatar image brendan ralph commented ·

I'm not really familiar with Atlas, but if you can send us (at devrel@) a Postman Collection showing a call that works, I'm sure we can provide the feedback on how to form the call in an http.request in Cloud Script.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.