Network Error while connecting to local mongodb server

The setup is in the local system

I have Mongodb server running in Windows

2nd I have my C code running in virtual box

3rd I have mongodb shell ‘mongosh’ to test queries and operations directly to my database in virtual box.

But it is showing Network Error. I want to store the data in mongodb in windows by using C code that is in RHEL8 in virtualbox.

The IP address of your Windows host is not the same as the IP address of your virtual machine. In addition localhost on your virtual machine refers to the virtual machine. The localhost of Windows refers to the Windows host.

When you connect from the virtual machine, you must specify the IP address of your Windows host.