Only allowing my server & local mongoDB compass to interact with database

I have a registration form page in production phase on Ubuntu server.
Simply, when I’m turning auth to true, I’m not able to submit my form, and when auth is not true, anyone can manipulate the database. What I want is that only my server (as registration form) is able to read and write the data in the database and I as an admin can connect from compass locally to the database, anyone other than that should be restricted.
I’m struggling with this from couple of days, kindly help me with this if you can.

Hi @Mani_Singh, welcome to the community.
Can you please take a look at this:

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Namaste Sourabh,
Thank you so much for this. I read that but it seems too much of information, as in, I’m not able to specifically locate the solution. If you could please help in figuring out as to what could be the best solution to start with, it’ll be easier for me.
Regards,
Mani

Namaste @Mani_Singh,
If you are using Atlas for Database deployment, you can simply click on the Network Access tab in the left panel and then click on ADD IP ADDRESS as illustrated below, and add all the IP addresses that you want(your Ubuntu Server, your machine which is running Compass etc.):

And in case you are not using Atlas, you can add the IPs that you want in your Mongod configuration file, under net → bindIp section like below:

systemLog:
   destination: file
   path: "/var/log/mongodb/mongod.log"
   logAppend: true
storage:
   journal:
      enabled: true
processManagement:
   fork: true
net:
   bindIp: <--Your Ubuntu server's IP address-->
   port: 27017
setParameter:
   enableLocalhostAuthBypass: false
...

Read more about configuring your mongod.

Also, as per the net.bindIp’s documentation:

The hostnames and/or IP addresses and/or full Unix domain socket paths on which mongos or mongod should listen for client connections. You may attach mongos or mongod to any interface. To bind to multiple addresses, enter a list of comma-separated values.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer