Once this is done, you can just replace my fake API key (highlighted in yellow) with your own key.

Now that this is ready, we just have to test it by repeating the same CURL command we used before. Feel free to use another movie title if you have a better one in mind ;-).

I removed the previous test we made before adding the trigger and now this is what I have in my collection:

Let’s review for a second what we have done:

We inserted a new document using an HTTP POST service hosted by MongoDB Stitch containing only an “_id” (automatically populated by MongoDB) and a “Title”.

The insertion of this document is detected by the trigger that calls an external Web API using this “Title” as the parameter.

We are then parsing the body of the result we get from this API and updating the document we inserted a few milliseconds ago.

Conclusion

With just a few lines of code, you can enrich the data where it lives with MongoDB Stitch. This is a great way to leverage your micro services architecture and finally switch to an event-driven architecture.

Next Steps

Thanks for taking the time to read my post. I hope you found it useful and interesting.

If MongoDB Stitch is something you are considering in production, you can discover here how the billing works.