Inserting records into Mongodb using Pymongo is using up my RAM incrementally and is eventually exhausting all memory
You can set the WiredTiger cache size, see hardware considerations.

Other than this, run MongoDB on containers (Kubernetes, Docker, rkt), where you can easily control resource usage. If you are using systemd for running MongoDB, you can also set resource usage.