duanaozhong0696 2019-02-19 14:02
浏览 385

通过SSH golang连接到mongoDB

I need to connect to remote mongoDB server via ssh, i was doing this earlier with mysql and its looks like :

sshcon, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", sshHost, sshPort), sshConfig)
    if err == nil {
        defer sshcon.Close()
        mysql.RegisterDial("mysql+tcp", (&ViaSSHDialer{sshcon}).Dial)

Is there a similar function like mysql.RegisterDial in mgo package?

  • 写回答

1条回答

  • 普通网友 2019-07-23 21:35
    关注

    It really does not make sense to add the tunneling function into your code. A simple wrapper shell script prevents you from the necessity to reinvent the wheel:

    #!/bin/bash
    
    ssh $USER@$MONGO_HOST -L $LOCAL_PORT:127.0.0.1:27017
    ./yourApplication "$*"
    

    With this, you can call your program via the wrapper as usual.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器