On Docker for Mac, you can use host.docker.internal
if your mongo is running on your localhost. You could have your code read in an env variable for the mongo host and set it in the Dockerfile like so:
ENV MONGO_HOST "host.docker.internal"
See here for more details on
https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds