how to connect another machine mongodb database inside local network ?

后端 未结 3 1844
傲寒
傲寒 2021-01-05 11:00

I follow this mongoose document enter link description here

mongoose.connect(\'mongodb://localhost/waterDB\');

Using This, I can connect lo

相关标签:
3条回答
  • 2021-01-05 11:31

    You will have to use SSH tunnel in this case. Refer to the following link which shows how you can create SSH tunnel.
    Node.js SSH Tunneling to MongoDB using Mongoose

    0 讨论(0)
  • 2021-01-05 11:33

    Try without the Port no.

    mongoose.connect('mongodb://192.168.1.100/waterDB');
    

    this should work for you.

    But make sure both are connected on the same network, if you are connected on other network than your server is, then it wont work

    0 讨论(0)
  • 2021-01-05 11:57

    It might be a problem with your MongoDB instance listening on localhost only. You can change the bind address in MongoDB's configuration file. The config file may be located in /etc/mongodb.conf or /etc/mongod.conf. There are also 2 config file formats:

    Old format (still supported):

    bind_ip = 0.0.0.0
    

    YAML (version 2.6+):

    net:
        bindIp: 0.0.0.0
    

    After changing the config file you have to restart the MongoDB server.

    0 讨论(0)
提交回复
热议问题