Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

windows subsystem for linux - Installing MongoDB in WSL

I was trying to install MongoDB in WSL running Ubuntu 18.04 after seeing this documentation. But MongoDB says that:

IMPORTANT
The mongodb package provided by Ubuntu is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you have already installed the mongodb package on your Ubuntu system, you must first uninstall the mongodb package before proceeding with these instructions.

MongoDB also says that WSL doesn't support mongodb-org

WINDOWS SUBSYSTEM FOR LINUX (WSL) - UNSUPPORTED
MongoDB does not support the Windows Subsystem for Linux (WSL).

So, I installed mongod using sudo apt install mongodb and when I ran mongo it shows the error:

connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-06-21T13:33:40.606+0530 E  QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017

Is there is a way to install the appropriate package and make it running?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have come across this situation recently.

Even though MongoDB says that it is not supported in WSL, you can actually install it. So, I suggest you follow that steps given in MongoDB docs.

Note : If you have already installed mongodb please remove all those before you install mongodb-org since it may cause some issues during installation :

sudo dpkg --remove --force-remove-reinstreq mongo-tools
sudo dpkg --remove --force-remove-reinstreq mongodb-server-core
sudo apt-get --fix-broken install

For installing mongodb community edition, I have added the commands below:

wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

sudo apt-get update
sudo apt-get install -y mongodb-org

Now, to get mongoDB running,

sudo nano /etc/init.d/mongod

and paste the contents in this link into the file and save it.

#give permissions
sudo chmod +x /etc/init.d/mongod

#start the service
sudo service mongod start

Now, you can run mongo to reach the database.

Hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...