Cannot start MongoDB on WSL
Solution 1
Here's a very important (blockquoted with a red background, no less!) excerpt from the exact link to the MongoDB docs you gave:
MongoDB does not support the Windows Subsystem for Linux (WSL).
However, it should still work, they just won't support it and the version they provide in the package mongodb-org
won't work right. I suggest following Microsoft's guide located here which is part of a larger Python guide. Find the "Install MongoDB" section about halfway down the page. Note that the service is named mongodb
here and not mongod
.
Solution 2
I was able to fix the
mongod: unrecognized service
issue by performing the following tasks:
sudo nano /etc/init.d/mongod
then copy and paste the content from this url and save it (you can use vim or any other text editor)
After that give executable permission
sudo chmod +x /etc/init.d/mongod
Now you will be able to start the service by following command
sudo service mongod start
Related videos on Youtube
![Amit Kumar](https://i.stack.imgur.com/5q7El.png?s=256&g=1)
Amit Kumar
I'm currently pursuing Bachelors in Information Technology Engineering from India. I do some competitive coding. I'm learning Web Development, Android Development. I have interest in Machine Learning, Computer Vision and Deep Learning.
Updated on September 18, 2022Comments
-
Amit Kumar almost 2 years
I have installed MongoDb, on WSL using the steps from the official docs here.
When i issue the command
sudo service mongod start
i get the following messagemongod: unrecognized service
.I've tried troubleshooting using these stackoverflow answers. I got it starting using one of the commands
sudo mongod --fork -f /etc/mongod.conf
However I cannot stop mongod using
sudo service mongod stop
. In fact mongod keeps running even after i close WSL. Is the documentation wrong? Or am i doing something wrong? Why wont the commands listed in the docs work?If I keep using the above command to start mongodb will it affect the data that i store?
-
Aaron Gong about 4 yearsThis works with the installation instructions in the official MongoDB documents which install the mongodb-org package. You need the additional instructions if you are using WSL Ubuntu because somehow the service is not created. Doing "sudo apt-get install mongodb" installs a totally seperate MongoDB package, which may not be as updated as the official one.
-
Roaim about 4 years@AaronGong you are absolutely right
-
Gabe Rogan over 3 yearsconfirming this works with latest official instructions for mongo 4.4, wsl2 and ubuntu 20.
-
theredcap over 3 yearsin the latest wsl2, if i could not find the daemon
mongd
instead triedmongodb
and it worked, also the file was already there inetc/init.d/mongodb
not needed to copy it from the github. Thanks :)