Search code examples
mongodbnginxnginx-config

MongoDB live server at http://127.0.0.1:27017/ says "It looks like you are trying to access MongoDB over HTTP on the native driver port."


I have taken project from GitHub for my college project and I have no idea about this technology. The project is on creating online education platform. There where few errors like not having .env file in project to connect to server. I already fixed that. I downloaded MongoDB from official website and I started server on 127.0.0.1:27017 created new database named virtual_class and also created all the collection inside it (from his YouTube video | Link: https://www.youtube.com/watch?v=9P7LzhL5i3w | GitHub link: https://github.com/MahbubulHasanSakib/virtual_classroom_deploy). I configured my .env file as MONGOURI = mongodb://127.0.0.1:27017/virtual_class. Now when I run the program database is connected successfully but when I open the URL in browser i.e., 127.0.0.1:27017 it says It looks like you are trying to access MongoDB over HTTP on the native driver port. I have searched many threads but all they provide is the solution for only Linux platform and not for Windows.

I tried to connect this project with nginx by configuring nginx.conf file as mentioned in How to setup MongoDB behind Nginx Reverse Proxy Here is how I configured


events{
       ...
}
stream {
    server {
        listen  27017;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass    stream_mongo_backend;
    }

    upstream stream_mongo_backend {
      server 127.0.0.1:27017;
  }
}

http{
     ...

when i run localhost on port 80 it says

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

I have also tried Cannot access mongodb through browser - It looks like you are trying to access MongoDB over HTTP on the native driver port but it seems to be the solution for Linux platform

Hope my question is understood and sorry for bad English :)


Solution

  • You cannot connect to mongodb via HTTP. That means you cannot browse to it in your browser. The HTTP Interface and REST API was removed in version 3.6.

    If you want to connect to your database you can use the Node native driver or use the mongosh shell.

    There are a number of other Node packages that will allow you to connect such as mongoose but that should be enough to get you started.

    Edit:

    I just checked the repo you are using and that app is listening on process.env.PORT so if you have already created your .env file and you have a PORT constant defined, for example, PORT=3000, then you can browse to your app on http://localhost:3000/. That repo is already using mongoose too so the app will be able to connect.