Node.js SSH Tunneling to MongoDB using Mongoose

前端 未结 3 1963
滥情空心
滥情空心 2021-01-02 06:05

I have two Mongo DBs. One for my dev environment, one for production as seen here from my Robomongo setup:

The production db is SSH tunneled to my Digital O

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-02 06:32

    Or if you don't want to change your code, provided that you have your ssh public key on the tunnel server, you can create a tunnel via ssh on the terminal:

    ssh -fNL :: @
    

    Example with made-up IPs connecting to a fake AWS EC2 AMI Linux

    ssh -fNL 27000:101.202.10.20:27000 ec2-user@33.44.55.66
    

    Now this mongoose.connect('mongodb://localhost:27000/mydbname'); works like a charm. ;)

提交回复
热议问题