Skip to content

Instantly share code, notes, and snippets.

@eagskunst
Created August 15, 2020 17:08
Show Gist options
  • Save eagskunst/59086fd32479ede3067688a74d7e21bc to your computer and use it in GitHub Desktop.
Save eagskunst/59086fd32479ede3067688a74d7e21bc to your computer and use it in GitHub Desktop.
Run a MongoDB server from Windows and connect to it from WSL2 Ubuntu
  1. Start PowerShell/CMD as admin and run the following command: mongod --dbpath="C:\Program Files\MongoDB\Server\4.2\data". --bind_ip=0.0.0.0

Your server now must be running

  1. From the unix terminal (Ubuntu in my case) run the following command: cat /etc/resolv.conf The output should be something like this (if you have automatic generation enabled, which it is by default:
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 122.1.1.1

And copy the direction from nameserver.

  1. Set the Mongo URI for your client with the IP that you have copied. E.g for Flask it would be something like this:
app.config['MONGO_URI'] = 'mongodb://122.1.1.1:27017/<your_db_name>'

The default port for a mongodb server on your local is 27017

  1. Run your app and the connection should work.
@leiberbertel
Copy link

It's been a long time coming, but it really worked for me. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment