0

In my app i'm using node with mongoose to connect to MongoDB. The MongoDB instance is in Azure. I'm needing the above so I can connect directly to the database.

After looking at this to do it: How to connect Robomongo to MongoDB

I'm using Robomongo for the client to do this. How do i find the connection string?

EDIT: currently IP and port results in 'network unreachable'. I've tried logging mongodb mongoose connection variable in my node app, and using these details doesnt work either.

Community
  • 1
  • 1
sledgeweight
  • 7,685
  • 5
  • 31
  • 45

2 Answers2

0

You can try to create an SSH Tunnel in your mongodb server VM, and connect the the mongodb server via this tunnel. You can refer to he similar scenario at https://azure.microsoft.com/en-us/blog/create-your-own-dedicated-mysql-server-for-your-azure-websites/.

After installing the mongodb in the VM, please try to following commands, which works fine on my side at last:

  • sudo iptables -A INPUT -i eth0 -p tcp -m tcp --dport 27017 -j ACCEPT
  • sudo netstat -anltp|grep :27017
  • sudo ssh -fNg -L 27017:127.0.0.1:27018 azurevmuser@servername
  • Create an endpoint for the port 27018 in the dashboard of the VM in Azure management portal

Then you can connect to the mongodb via the following code:

 var mongoose = require('mongoose');
    mongoose.connect('mongodb://<your_server_vm>.cloudapp.net:27018/test');
    var db = mongoose.connection;
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', function() {
     console.log("we're connected!")
    });
Gary Liu
  • 13,758
  • 1
  • 17
  • 32
0

It turns out Azure was having server issues that day (!). You can read updates here:

https://azure.microsoft.com/en-gb/status/

Also, I used the Azure machine URL to connect to mongo, generated by Azure when you create a new machine, not the IP, which i imagine is for security reasons.

So i used: nameofmymachine.cloudapp.net:27017 and added details under the SSH tunnel tab (which will use IP of course) for completeness.

sledgeweight
  • 7,685
  • 5
  • 31
  • 45