What is the method to retrieve the IP address of the source accessing the MongoDB database?

I'm looking to enhance the security of my database by allowing access requests only from the app server (which runs on backend using node.js and express.js).

However, when I whitelist the IP address of the app server (Azure App Service Linux), the connection breaks. I tried whitelisting the web server as well (frontend React Azure App Service Windows) but it didn't solve the issue.

Interestingly, when I whitelist 0.0.0.0 it works fine. This raises the question: if it's neither the app nor the web making the request, could it be the user? And how can I gather more information about these requests?

Thank you for your input.

Answer №1

Start by configuring your firewall to block all incoming connections from IPs outside of your app server, except for the IP address of your app server and allow access to your database server on port 27017.

Make changes to the /etc/mongod.conf file.

Ensure that the following lines are added below the comment # network interfaces:

net:
  port: 27017
  bindIp: 0.0.0.0

You can verify your setup by installing a MongoDB desktop client such as Robo 3T and whitelisting the IP address of your home/office computer in your server's firewall on port 27017.

To check which IPs are accessing your database, refer back to your /etc/mongod.conf file and locate the section marked # where to write logging data. This is typically found at a path like /var/log/mongodb/mongod.log

You can view your log file in the terminal using the command:

sudo cat /var/log/mongodb/mongod.log

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The maximum date setting in the Material UI MobileDatePicker is not functioning correctly

I am having trouble understanding how to use the maxDate prop in the MobileDatePicker component. Whenever I attempt to set it as maxDate={new Date()}, I find that I can still select dates beyond the current date. Visit this codesandbox for more details &l ...

Check access tokens from various front-end applications (Client ID) with the help of okta-jwt-verifier

Is there a way to verify access tokens generated from multiple front end Angular apps using the same backend API by sending in an array of clientIds? const OktaJwtVerifier = require("@okta/jwt-verifier"); const oktaJwtVerifier = new OktaJwtVerifi ...

How to set a background image in next.js with the help of MUI

English is not my first language, so please bear with me. I am currently working on a search engine home page in next.js 14 and I have encountered an issue. I want to incorporate a background image with a dark filter under the search bar. However, my curr ...

Is it possible to simultaneously run both an npm server and a proxy in separate directories with just one command in

We are currently working on a project that involves a 'server' folder and a 'client' folder. In order to run the project, we have to navigate to the 'server' folder, enter 'npm run nodemon' in the terminal, and then ...

Why can't Material-UI Textfield accept both type and maxlength simultaneously?

I'm currently working on a project using Material-UI in combination with React and TypeScript. <TextField id='user-id' label='User ID' type='number' required helperText='Required' inputProps={{ m ...

Tips for executing a SOAP request using NodeJs

Despite my efforts in researching various blogs, tutorials, and videos, I still can't find a clear answer on how to execute a RESTful request. For example, in NodeJs, you would code the request, hit the route (https://localhost/3000/api/getStudent), a ...

Apache SSI embraces both includes and nodes

My Apache server is up and running, serving SSI includes perfectly when my application is deployed through Apache. However, I'm now looking to deploy a node test server while still having Apache understand the SSI includes. Is this even doable? I cur ...

Encountered CSRF validation error while working with a Python Django backend in conjunction with React frontend using Axios for making POST requests

I recently completed a tutorial at and now I'm attempting to add a POST functionality to it. Despite obtaining the csrf from cookies and including it in the "csrfmiddlewaretoken" variable alongside a test message in json format for the axios function ...

Finding a way to compare the input from `process.stdin` with a string in Node.js

I came across a solution at the provided link, but even after implementing the suggested code changes, it still doesn't work as expected. The output only contains the data without the log message inside the if statement. I have also attempted using to ...

Retrieve a dynamic hex color variable for Tailwind CSS using Next.js

I need to dynamically change the colors based on a hex code retrieved from a database. In my variables.js file: const primaryColor = "#000000"; const secondaryColor = "#ff0000"; const notCheckedColor = "#9CA3AF"; export { primaryColor, secondaryColor, no ...

I encountered an infinite loop issue with Material UI tabs when loading my component within the navigation bar (AppBar > TabPanel)

I am currently working on an application for a school project, and I'm incorporating Material UI into it. Following the official documentation provided on their website. This is the link I have been referring to: Code. My goal is to load a new comp ...

Press the icon button within the card component without selecting the entire card

I have a card component with a clickable icon button inside it. I want to be able to click the icon button without triggering the ripple effect on the whole card. Currently, clicking the icon button causes the ripple effect to run on the entire card. Howe ...

Improving Mongodb's toArray() function for better performance

Currently, I am working with a 'matches' collection that contains 727000 documents. This collection has 6 fields consisting of simple integers and object Ids, with no arrays involved. To query this collection, I am using the following code: matc ...

What is the best way to utilize a submodule within a module on Node.js without external help?

Looking to utilize the 'utils-merge' node module that is included as a dependency of express 4.12.3 within my server application. I have successfully installed express on my server. I attempted: var merge = require('express/utils-merge&apos ...

Tips for correctly specifying the theme as a prop in the styled() function of Material UI using TypeScript

Currently, I am utilizing Material UI along with its styled function to customize components like so: const MyThemeComponent = styled("div")(({ theme }) => ` color: ${theme.palette.primary.contrastText}; background-color: ${theme.palette.primary.mai ...

Is there a way to allow an HTML page rendered by node.js to communicate back to its corresponding node.js file?

I am currently in the process of developing a registry system using node.js and HTML. However, I have encountered an issue where my HTML page is rendered by node.js, but when trying to call it back to the node.js file, it appears that the JS file cannot be ...

Tips for utilizing variables as the initial value of a JSON Object

Here is a JSON configuration example: { "Users" : { "182723618273612" : 15, "AddedUser" : 1 } } I have generated this field using a JavaScript function, but now I want to change the name of "AddedUser" ...

Guide to implementing scheduled tasks in a Node.js API using Express

Currently, my Node API has multiple endpoints, and while they work well for the most part, there is one endpoint that struggles with processing large requests taking up to 1 hour. To handle this, I am considering implementing a system where instead of wait ...

Grasping the idea of elevating state in React

I can't figure out why the setPostList([...postList, post]) is not working as expected in my code. My attempts to lift the state up have failed. What could be causing this issue? The postList array doesn't seem to be updating properly. I'v ...

Is there a way to trigger an Axios response without repeated calls or the use of a button?

As I navigate my way through using react and Axios, I encountered an issue with a get request in my code. Currently, I have a button that triggers the request when clicked, but I want to eliminate the need for this button and instead have the information d ...