Getting "'mongoimport' is not recognized as an internal or external command, operable program, or batch file." when trying to import data from a file
Asked Answered
S

28

54

New to MongoDB. I'm following this tutorial, and I get the above error when trying to follow Step 2. I'm putting the command into a Windows Command Prompt, and I've set my directory to the location of the 'mongoimport' file (C:\MongoDB). I've also included the same directory in my PATH, and the primer-dataset.json file is saved in that location. I'm fairly confident MongoDB is installed properly.

Sensory answered 25/6, 2015 at 16:18 Comment(0)
E
66

From Version 4.4.0 You have to install the MongoDB Database Tools separately, mentioned here.

To install.Then to go the bin directory of Tools (mostly C:\Program Files\MongoDB\Tools\[version]\bin) and open command prompt there.

Now execute the command here. This should work or else add .\in the beginning as mentioned by Cody w above.

If you want to execute your command from your current path (not only from mostly: C:\Program Files\MongoDB\Tools...\bin Path), you can do step 3 of this link (Make the DB Tools available in your PATH)

Enid answered 12/8, 2020 at 1:58 Comment(2)
oh wow ... I was on 4.4 and was wondering why PATH didn't work. cool thanks.Bethanybethe
Be aware Virustotal flags the Windows download as having a password stealing Trojan built in. (Trojan-PSW.Agent)Emperor
A
37

This error message means that there is no PATH in your system for mongodb server folder. Follow these steps (for Windows OS):

  1. Navigate to C:\Program Files\MongoDB\Server\[your_server_version]\bin.
  2. Copy this path.
  3. In start menu search for View advanced system settings and open it.
  4. Select Advanced tap.
  5. Click on Environment Variables button.
  6. In the System Variables list find element Path, select it and click Edit.
  7. Paste the path which you copied before. [IMPORTANT for windows 7] don't forget to put a semicolon in front of the path to separate this new path for the others. Like this ;C:\Program Files\MongoDB\Server\4.0\bin.
  8. Click OK button for all opened windows.
  9. Close all opened Command Prompt windows.
  10. Open a new Command Prompt window and try again.
Adipose answered 4/10, 2018 at 14:50 Comment(2)
In my case restart was required.Witherite
This was the clearest guide I've ever found anywhere on adding directories to the path variable.Cornetcy
J
25

I had the same problem. You need to navigate in command prompt to where your mongoimport.exe file lives. Then try running that command in the tutorial. You should also put that example .json file in that same directory

Julianajuliane answered 4/7, 2015 at 4:50 Comment(0)
E
14

In my case I downloaded the mongodb tools externally from their official website MongoDbOfficial

Then I clicked Tools to download locally

enter image description here

Then I scrolled down and clicked Mongodb Database Tools

Then I download it, it will download as Zip file.

Just extract it and this zip file has a bin folder, copy-paste all the .exe files

And place it in your 4.4/bin folder and problem solved

Then you can open a command prompt and run as administrator, and make sure it has the correct path as:

cd C:\Program Files\MongoDB\Server\4.4\bin

Then write the mongoexport command

Erlindaerline answered 24/11, 2020 at 12:4 Comment(1)
In my case the tools were downloaded with an extensive tool prefix. Removed the prefix, such that the it was just 'mongoimport.exe' - worked fine.Desdamonna
B
12

If you are using MongoDB 4.4 then you need to separately download the tools. You can use the following link: https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools

Brain answered 25/8, 2020 at 8:23 Comment(1)
Thanks for the answer its helped me. just download package from the above link. if you want only the importdb operation then copy that exe file alone and paste in this folder(C:\Program Files\MongoDB\Server\4.4\bin.).. Thats all.Underthrust
C
8

In my case the mongoimport command was not available by default on the system (windows PC), so first download from the official website the additional tools provided by MongoDB, this includes mongoimport and others that you may not need.

after installation copy mongoimport.exe from "C:\Program Files\MongoDB\Tools" into the bin folder "C:\Program Files\MongoDB\Server\4.4\bin"

navigate using your terminal to the folder where the json file you want to import is located then run your mongoimport command.

Claudineclaudio answered 16/9, 2020 at 12:49 Comment(0)
C
8

This is because you don't have the mongoimport binary in bin folder, you can solve this issue by doing:

  1. Go to Mongo developer tools website.
  2. Download the Zip file for your system and extract it.
  3. Copy bin folder files to your install path. (default for 4.4: C:\Program Files\MongoDB\Server\4.4\bin)
Corrinecorrinne answered 24/6, 2021 at 10:24 Comment(0)
D
6

I had to do the same as Megaforce1020, but I had to add .\ in front of mongoimport.

.\mongoimport --db test --collection restaurants --drop --file primer-dataset.json
Duad answered 1/7, 2016 at 9:50 Comment(0)
F
5

I had the same problem. You need to download the MongoDB database tools zip file from here and copy-paste all the files of the bin folder into C:\Program Files\MongoDB\Server\4.4\bin folder. And now all is set.

Foredate answered 24/2, 2021 at 14:45 Comment(0)
H
5

Unfortunately, you have to download MongoDB tools separately from mongodb website.

.zip

By default, the .zip option is enabled. After downloading the MongoDB tools and extracting them, open the bin folder and copy it. Then go to the bin directory of MongoDB (C:\Program Files\MongoDB\Server\<your MongoDB version>\bin) and paste them in it.

.msi

If you downloaded .msi instead of the .zip file, after the installation is completed, go to the C:\Program Files\MongoDB directory. You can see a folder with the Tools name right side of the Server folder. You should go to the bin folder of the Tools and copy all files in it, go back to the Server folder, open the bin folder and paste all of them on it right side of the mongod file.

Higgs answered 26/12, 2021 at 19:36 Comment(0)
J
4

The error refers to 'mongoimport'; the location of the JSON file is independent of this error.

The PATH directory may have been setup improperly. Make sure the folder given in the path contains the application.

In my case, the path is C:\mongodb\bin.

Joinder answered 19/5, 2016 at 19:11 Comment(0)
E
4

I've had a similar problem. After some research it turned out that my environment variables were set incorrectly.

For some reason they were set to C:\Program Files\MongoDB\Server\3.2\bin, even though I was running version 3.4 and it should have been C:\Program Files\MongoDB\Server\3.4\bin. After changing and restarting the console everything was working.

This is the tutorial I followed:

http://www.acemyskills.com/wp-content/uploads/2015/08/Environment-Variables.png

Embed answered 6/1, 2017 at 10:54 Comment(0)
K
4

MAC USERS: I was able to do the mongoimport by executing it from within the same folder where mongoimport.exec is located. I had to write it like this: ./mongoimport and then the rest of the script.

Hope it can be useful. Happy Coding.

Kerwon answered 25/1, 2020 at 20:37 Comment(0)
F
4

First I went to the official website of MongoDB in my case and downloaded the MongoDB Database Tools and it was downloaded in MSI. Here is the link and screenshot image: [1] https://www.mongodb.com/try/download/database-tools. [1.1] https://prnt.sc/12d95ya

Then I open the folder of my c drive and from there copy all the files of the developer tools and paste it in the bin folder of my main MongoDB server. My file Explorer Screenshot Images Link: [2]: https://prnt.sc/12d98ji [3]: https://prnt.sc/12d99zb

Fabozzi answered 1/5, 2021 at 19:50 Comment(0)
G
3

for windows user: first of all, you need to make sure that you add your MongoDB path to environment variable for that go to control panel > System & Security > System > Advanced System Settings > Environment Variables > navigate to the Path variable hit Edit and add your MongoDB path in my case "C:\Program Files\MongoDB\Server\4.4\bin"

but if you still have the issue "command not found" you need to go to this link https://www.mongodb.com/try/download/database-tools and download "The MongoDB Database Tools" it gives you a bin that contains mongorestore , mongoexport , mongoimport, and more things that you can't find in the command prompt, copy them, and past them in MongoDB path.

it will work,

Geostatics answered 15/9, 2020 at 16:8 Comment(0)
M
3

Got this error after installing 'MongoDB Compass' seperately (wasn't able to install it through Mongo DB installation for some reason), even after editing the enviroment variables & reastart.

Problem fixed after downloading MongoDB Command Line Database Tools Download and just copying (without further installation) the 'mongoimport.exe' file from the batch download to the existing MongoDB folder in program files (if your version isn't 6.0 adjust the path to yours):

C:\Program Files\MongoDB\Server\6.0\bin

Malapropism answered 25/11, 2022 at 14:27 Comment(0)
S
2
  1. open a command prompt
  2. Navigate to the folder - C:\Program Files\MongoDB\Server\4.2\bin
  3. run command "mongoimport --help"
Stringency answered 19/4, 2020 at 19:17 Comment(0)
Z
2

From MongoDB 4.4 onwards you have to download the mongoDB tools zip folder.

  1. You unzip it, get to the bin folder inside it.
  2. You then copy the address of the bin folder and set that as an environment variable.
  3. Now you can use mongoimport anyhere. But when you do use it, make sure you navigate to the folder where your data/json file is immediately visible.
  4. THEN use mongo import - blah blah and it should work
Zygote answered 3/10, 2020 at 5:37 Comment(0)
M
2

use this link to download files https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools then go to C:\Program Files\MongoDB\Server[version you are using]\bin And paste mongoimport.exe from bin folder of download. if your want to import other tools as well then paste all files

Musclebound answered 18/4, 2021 at 12:22 Comment(0)
I
2

I can see two possible reasons for this error.

  1. You have not setup the environment variable. To setup the environment variable, follow below steps. a. Copy the path of bin folder saved in your system, i.e. C:\Program Files\MongoDB\Server\version_number\bin. b. Click on Windows button and type Edit the system envionment variables and click Open. c. Click on "Environment Variables" button. Under "System Variables", find Path, select it and click Edit. d. Paste the path which you copied before.

  2. Chances are that mongoimport.exe is missing in the bin folder a. Navigate to https://www.mongodb.com/try/download/tools in the browser and download the suitable version. b. Copy the downloaded contents (copy only files, not bin folder) into C:\Program Files\MongoDB\Server\version_number\bin c. Head back to command line and try the below command mongoimport --db dbName --collection CollectionName --drop --file jsonFileName.json --jsonArray

Iloilo answered 5/1, 2022 at 6:28 Comment(0)
P
2

1.download and extract mongoDB database tool "https://www.mongodb.com/try/download/database-tools?tck=docs_databasetools" into this folder "C:\Program Files\MongoDB\Server\5.0\bin" as seen below

enter image description here

  1. You can start the terminal anywhere and use the mongoimport command

  2. if the error persist the check your Environment variable and follow the steps from @Fawzy Mokhtar

Plat answered 28/6, 2022 at 14:35 Comment(0)
D
2

For those who didn't find the answer:
Versioning Starting with MongoDB 4.4,MongoImport/DatabaseTool is now released separately from the MongoDB Server and uses its own versioning, with an initial version of 100.0.0. Previously, mongoimport was released alongside the MongoDB Server and used matching versioning.

Drabeck answered 18/8, 2022 at 10:23 Comment(0)
I
1

Download the MongoDB Database Tools from MongoDB official Website - https://www.mongodb.com/try/download/database-tools and Unzip the folder

Mongoimport.exe path

Method 1

1.) Copy the json file which contains the data to be imported in the same folder as mongoimport.exe

2.) For Windows open the command prompt and run cd (path to folder with mongoimport.exe)

3.) run command .\mongoimport.exe import_data.json -d database_name -c collection_name --jsonArray

example import successful

Method 2

1.) Add the mongoDB tools to environment variables.

Follow the instruction given on this link to add mongodb tools to environment variables - https://www.mongodb.com/docs/database-tools/installation/installation-windows/

2.) Copy the path of file which contains the json file to be imported

3.) Open Command Prompt and run - cd (path copied of file to be imported)

4.) Run Command - mongoimport import_data.json -d database_name_here -c collection_name_here --jsonArray

mongoimport

Inconspicuous answered 20/3, 2023 at 6:0 Comment(0)
E
1

Starting with MongoDB 4.4, the MongoDB Database Tools are now released separately from the MongoDB Server. Therefore you need to install all the toolset if your mongodb version is greater than 4.4.

  1. https://www.mongodb.com/docs/database-tools/installation/installation/[enter link description here]1 use this link and download all the tool set.
  2. Select your platform(Linux/windows/macOS).
  3. For windows, Download the Database Tools using https://www.mongodb.com/try/download/shell
  4. then follow following instructionsenter image description here
  5. or you can easily copy below downloaded tolls enter image description here
  6. And paste in your mongodb server bin folder List item

Click the Download button

Equitable answered 23/4, 2023 at 6:28 Comment(0)
F
0

download the mongodb data base tools. and inside the bin folder. we have all .exe file. copy all the file and paste into your /programfile/server/version/bin . this will resolve the problem

Fewness answered 2/8, 2023 at 9:39 Comment(0)
C
0

It worked for me

brew install mongodb-database-tools

Installing the Database Tools on macOS

Circumscissile answered 2/8, 2023 at 13:42 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Sanctuary
S
0

Try another way // script.js

use my_db;// db name

db.createCollection("data");//collection name

var jsonData = /* ... */;  // Replace this with your actual JSON data

db.data.insertMany(jsonData);

Then, you could use load() to execute this script in the MongoDB shell:

load('/path/to/script.js')
Superscription answered 14/1 at 8:41 Comment(0)
S
0

first download the mongodb database tools after that find the path till its bin file set the path in enviornment variables after that use the term "mongoimport" after this term add the path till your json file and after that "-d" for setting the name of database "-c" for setting the name of collection and add --jsonArray for adding the complete array to the database syntax : mongoimport "C:\Users\Aakash\first-app\mongo-demo\exercise\mongo.json" -d students -c values --jsonArray note: everything should be done in command prompt not in terminal of VS code or any other compiler

Sandeesandeep answered 15/1 at 7:18 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Sanctuary

© 2022 - 2024 — McMap. All rights reserved.