According to your code, you connect to IP 127.0.0.1 - which is your local machine. IP 127.0.0.1 (or more precisely any address from 127.0.0.1 to 127.255.255.254) makes a connection to your own computer and definitely not to any remote computer, unless you configured some port forwarding on your machine. But still, it would no make much sense, because when you are on the local machine then you could connect directly to the forwarded host.
You write “I have also a MongoDB installation on my local machine”. When you connect to mongodb://{user}:{password}@127.0.0.1:27017/, then you are exactly connecting to this instance.