How do I setup triggers from python

I want some of validation code to execute server side. I think triggers is a good fit for this purpose. To automate the setup it would be good to do the setup from python. But I don’t know how. It must be possible rigtht?

You could write a trigger that calls a lamba on AWS that’s in Python. Or you could have a API running somewhere and then just POST your data to that endpoint.

Triggers only support JS for now.

Well, I know that the trigger itself is written in javascript.
But my question is how I can do the setup of the triggers from Python.

Is there a compiler that writes python into js? That sounds like your best bet at this point. I think Realm might have plans to support other languages, but no idea when that will become available.
A cursory search found this: GitHub - metapensiero/metapensiero.pj: Javascript for refined palates: a Python 3 to ES6 Javascript translator

No, I’m sorry, I must be very unclear. Perhaps the solution is to obvious.
I use the python lib pymongo to talk to MongoDB.
I want to do something like this:

trigger_code_string = “java script code here”

But pymongo doesn’t have an insert_trigger method, so how do I do that?
Do you just put the trigger in the config db?

Hi there - we have a Admin API that lets you create triggers, so using it with a standard Python HTTP client might help here. Atlas App Services API

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.