I am doing setup on windows10 via wsl2. I’ve done everything from the guide uptill [Step 3: Start MongoDB and seed the database]. But after that when i type “mongod”, it shows error that command not found.
mongod: command not found
I presume you are installing MongoDB using their Windows Installer.
One of the core requirements of installing freeCodeCamp is Linux (or Linux like) environment. This means all software you need should also be within the Linux-based environment.
Here is an explanation of how WSL2-based installation behaves:
When you launch a WSL2 terminal (like the Ubuntu terminal in your screenshot), you are running a different operating system - Ubuntu, in your case, on your machine. WSL2 acts like a middleman.
You are running an OS within an OS (I am oversimplifying to keep this easier to understand).
Anything you install on the Windows side is NOT automatically made available on the Ubuntu side. I hope that makes sense.
As a fix, you will need MongoDB to be installed on the Ubuntu side; here are two ways:
Difficult - Follow the MongoDB Guide for Linux (Although I think I could not get it working properly).
Easy - Use Docker Desktop for Windows and then run MongoDB as a container.
Super easy - Use a cloud service like MongoDB Atlas. This works on all operating systems because you would use the correct URI from their dashboard.
Using Docker Desktop (not just the docker agent) for Windows makes life a bit easier because your services (containers like MongoDB or others like Postgres and MySQL) are exposed on both the Ubuntu side and the Windows side.
Anyways, the choice is yours. If you are really-really interested, we linked an article to a generic setup for Node.js + MongoDB + Docker on WSL2 in our guide that you followed. It should be in the footnotes. Trust me, I know the person who wrote it
First of all Thanks a ton for your reply. I really got to learn many things. Really grateful. But actually, I had referred the doc you mentioned and also used Docker Desktop and I can also see MongoDB in Docker’s container.
You encountered an error when installing mongodb-org - you need to ensure all required packages are correctly installed, before trying to use mongod
You cannot use mongod in the terminal, after starting mongodb in a container. This is expected, because your terminal session is not inside the container - you do not have direct (easy) access to anything in the container, and vice-a-versa.
If you want to continue with option 2 of using mongodb in a container, then you can work within the container context by using the docker exec command.
It looks like there is an error, when starting the container. I am not sure the steps you need to take to debug this, but getting more of the logs from the mongod instance would be helpful.