View JSON Data in any Browser, with URL

Hi Community,

is it possible to display my JSON file directly in the browser using a URL address?
For example, if I open this address:
https://jsonplaceholder.typicode.com/todos/1,
I can see the JSON file directly.

So would it be possible to call something like this?:
mongodb://name:pwd.mydatabase.json

you can use “API” services.

Hi @BG_G and welcome in the MongoDB Community :muscle:!

If you cluster is in Atlas, you can achieve this by creating a REST API in MongoDB Realm.

  1. Create a Realm App.

  1. Create a 3rd Party Services => HTTP

  1. Create a webhook

  1. Put this code in the function:
exports = function(payload, response) {
    const coll = context.services.get("mongodb-atlas").db("test").collection("users");
    return coll.find().toArray();
};
  1. Save & Deploy.

  1. I created the test.users collection in my Atlas cluster with 2 documents:

  1. Retrieve the URL from the webhook settings and voilà!

And of course, my piece of JS code is super basic but you can make it as complicated as you like, retrieve query parameters, pass them to the find query param, sort the results, etc.

Cheers,
Maxime.

2 Likes