Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to mongodb using mongoose and Fixie (Heroku add-on)

I have a mongodb database hosted on an Atlas MongoDB Cloud cluster. I'm currently accessing the database in my node.js application using mongoose:

mongoose.connect("mongodb://user:pw@cluster0-shard-00-00-***.mongodb.net:***,cluster0-shard-00-01-***.mongodb.net:***,cluster0-shard-00-02-***.mongodb.net:***/admin?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin");

Because Atlas MongoDB Cloud have a whitelist, and Heroku doesn't provide the possibility to obtain a fixed IP address for my application, I'm using Fixie add-on. Basically Fixie acts as a proxy for outbound traffic.

This way, I can request resources via HTTP, which are tunneled through a fixed IP address provided by Fixie. But what I do need is to connect to the Atlas Cloud cluster using Fixie's proxy, in order to retrieve and modify data from the database.

Can it be done using mongoose?

The mongoose.connect function accepts an option parameter, but I couldn't find any option regarding the establishment of a connection through a proxy.

like image 878
amaralbf Avatar asked Feb 14 '17 14:02

amaralbf


1 Answers

Just got a reply from Fixie's team:

Fixie is an http/https proxy, so it won't work for lower-level TCP connections like you'd need for your mongodb connection

When I asked about the possibility of using SOCKS for this case, they replied:

It looks like mongoose does not natively support socks proxies, and it does not accept a custom socket (which is how Node database drivers for MySQL and Postgres support it).

So apparently, in my case, there is no way to establish a connection to MongoDB Atlas cluster using mongoose through the proxy solution offered by Fixie (Heroku Add-on).

like image 115
amaralbf Avatar answered Oct 23 '22 13:10

amaralbf