简体   繁体   English

查找与Azure MongoDB的Robomongo连接设置的连接字符串

[英]Find connection string for Robomongo connection settings to an Azure MongoDB

In my app i'm using node with mongoose to connect to MongoDB. 在我的应用程序中,我使用带有mongoose的节点连接到MongoDB。 The MongoDB instance is in Azure. MongoDB实例在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 看完该方法后: 如何将Robomongo连接到MongoDB

I'm using Robomongo for the client to do this. 我正在为客户使用Robomongo。 How do i find the connection string? 如何找到连接字符串?

EDIT: currently IP and port results in 'network unreachable'. 编辑:当前的IP和端口导致“网络无法访问”。 I've tried logging mongodb mongoose connection variable in my node app, and using these details doesnt work either. 我尝试在节点应用程序中记录mongodb mongoose连接变​​量,并且使用这些详细信息也不起作用。

You can try to create an SSH Tunnel in your mongodb server VM, and connect the the mongodb server via this tunnel. 您可以尝试在mongodb服务器VM中创建SSH隧道,并通过此隧道连接mongodb服务器。 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/ . 您可以在https://azure.microsoft.com/zh-cn/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: 在虚拟机中安装mongodb之后,请尝试执行以下命令,最后在我这一边工作正常:

  • 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 在Azure管理门户中VM的仪表板中为端口27018创建端点

Then you can connect to the mongodb via the following code: 然后,您可以通过以下代码连接到mongodb:

 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!")
    });

It turns out Azure was having server issues that day (!). 原来,Azure那天遇到服务器问题(!)。 You can read updates here: 您可以在此处阅读更新:

https://azure.microsoft.com/en-gb/status/ https://azure.microsoft.com/zh-CN/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. 另外,我使用Azure机器URL连接到mongo,它是在创建新机器时由Azure生成的,而不是IP,我想这是出于安全原因。

So i used: nameofmymachine.cloudapp.net:27017 and added details under the SSH tunnel tab (which will use IP of course) for completeness. 所以我使用了: nameofmymachine.cloudapp.net:27017 : nameofmymachine.cloudapp.net:27017并在SSH隧道选项卡(当然会使用IP)下添加了详细信息,以确保完整性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM