How can I connect and use MongoDB Compass from Windows to MongoDb server on WSL2 - mongodb

I want to work with Mongo Compass running in Windows and connect to MongoDb server in WSL2.
Both MongoDb services are working fine (I can connect from Windows to MongoDb server on Windows and from WSL2 to MongoDb server on WSL2).
Windows build 19042.
Thanks!

Unless you are running a pretty old build (from 2018 or earlier) WSL includes a feature known as Localhost Forwarding, which should automatically allow you to use localhost in Mongo Compass in Windows to connect to the database running under WSL.
However, sometimes that features "breaks", especially if you hibernate or turn on Windows with the Fast Startup feature enabled (which is the default).
If this is the case, try wsl --shutdown and restart WSL. Then disable Fast Startup. If you do need to hibernate, remember that you may need to wsl --shutdown again to restore the forwarding mechanism.
See this answer for some additional details.

As far, as I understood, to access something running on WSL from you host-machine(Windows) you need to manually map host:port of your WSL MongoDB server to localhost.
This link describes the topic, I hope:
https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-a-wsl-2-distribution-from-your-local-area-network-lan
After mapping your port you probably will connect to your MongoDB server via Compass with mapped address and port.

Related

Can't connect to MongoDb 4.0.9 on Windows server with shell

I have MongoDb 4.0.9 running as a service on Windows Server 2016 Standard.
This is my mongod.cfg:
For testing purposes I turned off the server's firewall completely.
I am not using SSH or any other tunnel so far
The Windows service logs on as "Network Service"
I have one user in the "admin" database with roles "userAdminAnyDatabase", "dbAdminAnyDatabase" and "readWriteAnyDatabase"
My local machine is Windows 10 and here I have Mongo 4.0.9 installed as well. I am trying to connect to my server's database by shell:
When I go on the server (Remote Desktop) I can connect successfully (same user credentials):
I am running out of ideas what I am doing wrong when remote connecting.
What is also confusing: I am doing the exact same thing on another server (different provider, different database, but also Windows Server 2016 Standard, MongoDb 4.0.9 and the same user and roles). And here I CAN connect.
So, I assume it has something to do with the settings of Windows Server (and not Mongo ...)?
Does anybody have an idea?
From what I could gather, it seems your the Windows Machine running the MongoDB service is hosted in the cloud.
If you are certain the windows firewall is turned off (make sure to disable it on Private, Public and Domain - if applicable)
Furthermore, my best guess is that the port might be block by the cloud hosting provider firewall.
Usually they provide the basic port openings (21, 80, 443, 1433, 3389, etc) - and port which are not common for windows (like 27017) are blocked (filtered) by default.
if you wish to verify this, run the following:
nmap <server hostname> to get the default ports checked.
for MongoDB run nmap -p 27017 <server hostname>

Accessing WSL postgresql server from Windows PGadmin

I am running postgresql in WSL Ubuntu on windows. Everything is up to speed, my data is loaded and I wish to access the database through some graphical interface. I was thinking pgadmin4.
Is it possible to accomplish this through a windows install of pgadmin4? I installed pgadmin4 on windows and tried to connect the traditional way in the GUI through localhost but am not getting a connection. I figure there may be a special method here.
For everyone else stumbling across this: The best way to do this (that I know of) is to SSH into your local WSL and then configure the SSH in pgAdmin to that.
I have yet to figure out, how to use this remotely.
As long as postgres is running within your wsl2 instance (check with sudo service postgresql status) then within PgAdmin 4 (running in windows), all you need to do is click to "Register" a new server.
Then, while entering the Connection data, set host to localhost and port to 5432 (unless you specified unique port within your postgres instance when creating in wsl2.
See this answer for more detail
There is no special way needed, you should be able to get a connection. Just like your dev http ports are exposed to your browser on Windows, your db port should too.
I had to manually add localhost to pg admin though which is a bit weird.
Make sure your db service is up and running on Ubuntu, sometimes the db service is killed for no reason.
To see if your PostgresSQL service is up or not:
sudo service postgresql status
If it's not, start the service:
sudo service postgresql start

Cant Connect to MongoDB server from Client

I am trying to connect from my machine (client) to server, and it says I cant connect to server.
My machine is Windows 10 and Server machine is Windows Server 2016.
And I tried to connect from cmd and it gives me this error.
Help me with this problem please.
You should check the following items on the server running MongoDB.
Firewalls
Whitelists
You should also verify basic network communication using something like ping from the client to the server.
I will comment regarding Robomongo, seems like you are trying to connect to MongoDB 3.4 DB which only supported starting from the latest beta: Robomongo 1.1 - Beta version with MongoDB 3.4 Support

MongoDB Server Ubuntu 16.04

I've installed MongoDB on my Ubuntu 16.04 VPS and allowed connections through the firewall. When I run the server using the command (mongod), it starts without a problem and I can then connect to it (using RoboMongo as test application).
However, when I run the service automatically on startup (using systemctl), I cannot connect to it. I verified it was running, and could not run it myself as the address was already in use.
Does anyone have any experience with this, or any tips on how to solve the problem? The server will be running localhost only and I'm going to be using an SSH tunnel for testing purposes, so no authentication is necessary.
Anyone?
When you started mongod did you then provide a configuration file (using the --config or -f parameter)? If not then it defaults to listening on all interfaces.
The default configuration file which is used when starting the daemon with systemctl defaults to only listen on localhost preventing it from being available on the network. This is fine if you intend to connect to the server using a tunnel.

Access MongoDB from other server

I have a MongoDB database on my Linux server. I want to access it from another server. I tried to make a connection from my local computer with the Robomongo. The connection is succesfull, but the authentication fails.
How can I get the authentication credentials? Or should I change something in MongoDB before I can acces the database from another server / pc?
Someone else have set up this database, and there is no possibility to ask him this questions.
I have found the solution by my self:
The File etc/mongod.conf has a line 'bind_ip'. In this line, you originally have to add the IP address which you want to access your database. But, it don't work! You should better comment this line.
But, you don't have any authentication now, so you have to add authentication. Here you have an tutorial about this: http://ghosttx.com/2012/03/how-to-connect-to-a-remote-mongodb-server-with-mongohub-for-mac/
When you have done that, you have to enable authentication. You can do this by editing etc/mongod.conf again, and uncomment the line 'Auth = true'.
Now you can connect with you Mongo Database ;)
Ive sorted it by adding ssh option to RoboMongo following this link:
http://www.mongovue.com/2011/08/04/mongovue-connection-to-remote-server-over-ssh/
Im on OSX and connecting to Ubuntu 14 / Mongo 2.6.7 on VPS and when Ive added my ssh details to the Robomongo all seem to work ok (Ive also changed the mongo config to remove the ip_bing and enabled port 27017)
If you do not like to bother with authentication and stuff just make an SSH Tunnel:
ssh -fN -l username -i .ssh/id_rsa -L 9999:localhost:27017 remote.com
Just connect to mongodb on localhost:9999 and it will establish a connection to your mongodb on port 27017 on your server at remote.com.
Run your mongodb with following command to access mongodb from other servers
mongod --port 10945 --bind_ip 0.0.0.0
I was not able to use Robomongo with MongoDB 3.0 too (connecting from a Windows machine to a Linux one, using SSH). The only tool that works for me is MongoChef (http://3t.io/mongochef/).