How to bring Data to MongoDB to embed live data in Tape's dashboard app

Hi all

I thought I would share a quick first pass at building a dashboard.
I have imported a sample dataset into Tape


and then created an API link to a Mongo-Atlas Database, which pushes records up to Mongo for those who might be interested in sending data to Mongo I am using this:

const url = `https://europe-west1.gcp.data.mongodb-api.com/app/data-pbsul/endpoint/data/v1/action/insertOne`;
const response = await http.post(url, {
    headers: {
        "apiKey": collected_api_key_field_apikey_value,
        "Content-Type": "application/json"
    },
    data: {
        "dataSource": "Cluster0",
        "database": "TestIntergration",
        "collection": "t1",
        "document": {
            "acceleration": record_field_acceleration_decimal_value,
            "car": record_field_car_name_value,
            "cylinders": record_field_cylinders_decimal_value,
            "displacement": record_field_displacement_decimal_value,
            "horsepower": record_field_horsepower_decimal_value,
            "year": record_field_model_year_decimal_value,
            "mpg": record_field_mpg_decimal_value
        }
    }
});

console.info('data', JSON.stringify(response.data));
console.info('headers', JSON.stringify(response.headers));

const mid = jsonata('data.insertedId').evaluate(response);
tape.Record.update(current_record_id, {fields: {mongoid: mid}});

The above also updates the Tape record with the Mongo record ID which could be used for updates etc.

In Mongo we can build a dashboard (Mongo makes this really easy) then we can embed that in our Tape dashboard:

NOTE:
In case it is not clear the above :point_up_2:t3: image shows ‘live’ charts of the data within the Tape app

this will then update as the data changes:

I have done all this in a couple of hours including setting up Mongo Atlas Databases, finding the data set etc and I am packing to go away so this is not a long process and with some time and effort could be made to look a lot nicer :slight_smile:

Looking forward to what others manage to create

8 Likes

Hi Jason,

wow! Just mind blowing! :100: :rocket:
We are currently thinking about how we can best offer a live synchronization to MySQL, and you just solved it with a MongoDB! Really brilliant!

I think this will definitely inspire others and together with the embed block opens up completely new use cases.

Cheers
Leo

2 Likes

Amazing, Jason!

Did you use a push architecture on purpose, or do you think something similar is possible by pulling from Tape?
I think when we tried pulling we once ran into some limits…

2 Likes

Hi @Mario and thanks

Well for this demo it was the easiest and fastest way to achieve the goal. I am not a Mongo Atlas expert but to my knowledge, it is not able to make calls to other API’s directly so I would have needed to build something to sit between Tape and Mongo which as I was packing while building the demo seemed a little much :wink:

I don’t see why you can’t do the same by pulling through with more work (and something to sit between your DB and Tape) if you need to, I am not sure where you are meeting the limits.

1 Like

@Jason thank you for the reply. Ah I understand. Regarding your setup, this makes sense for sure.

I think we wanted to pull data with tape.Record.getManyOfView and ran into an error, but now that I checked the code again, I don’t remember why we had the issue. It seems you can just get the data using a cursor, which I remember differently.

Have a nice weekend :slight_smile:

2 Likes