Search code examples
mongodbmongoimport

How to mongoimport from any location in cmd


So right now I'm using mongoose to work with MongoDB (learning). Something I tried to do was import a JSON array by using

mongoimport --db mongo-testing --collection test --drop --file data.json --jsonArray

but it didn't work giving an error that mongoimport was not found. After looking around in StackOverflow, I found that you needed to run the command in the \bin\ folder where your mongo PATH variable points to. So I did just that.

mongoimport --db mongo-testing --collection test --drop --file /d/Node/mongo-test/data.json --jsonArray

The command above I ran in the \bin\ folder and pointed the file via an absolute path and it worked! However, I don't think that's the right way to do it.

Question: Is there a way I could run the command in /d/Node/mongo-test/ file where my Node.js project is or do I need to go to the bin folder each time

bin folder for mongo

enter image description here


Solution

  • UPDATE: So I tried downloading the zip file instead of the msi. After downloading it, copy it into mongoDB path in ProgramFiles (beside Server is where i put it).

    C:\Program Files\MongoDB\mongodb-database-tools-windows-x86_64-100.2.0\bin

    Add the above line into ur PATH variables (if you put it in the same spot).

    Close all terminals and if you are using VSC terminal, close the program and restart it.

    This worked for me! Hope it helps someone too