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.
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)
This error message means that there is no PATH in your system for mongodb server folder. Follow these steps (for Windows OS):
- Navigate to
C:\Program Files\MongoDB\Server\[your_server_version]\bin
. - Copy this path.
- In start menu search for View advanced system settings and open it.
- Select Advanced tap.
- Click on Environment Variables button.
- In the System Variables list find element Path, select it and click Edit.
- 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
. - Click OK button for all opened windows.
- Close all opened Command Prompt windows.
- Open a new Command Prompt window and try again.
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
In my case I downloaded the mongodb tools externally from their official website MongoDbOfficial
Then I clicked Tools to download locally
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
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
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.
This is because you don't have the mongoimport
binary in bin folder, you can solve this issue by doing:
- Go to Mongo developer tools website.
- Download the Zip file for your system and extract it.
- Copy bin folder files to your install path. (default for 4.4:
C:\Program Files\MongoDB\Server\4.4\bin
)
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
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.
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.
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
.
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
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.
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
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,
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
- open a command prompt
- Navigate to the folder - C:\Program Files\MongoDB\Server\4.2\bin
- run command "mongoimport --help"
From MongoDB 4.4 onwards you have to download the mongoDB tools zip folder.
- You unzip it, get to the bin folder inside it.
- You then copy the address of the bin folder and set that as an environment variable.
- 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.
- THEN use mongo import - blah blah and it should work
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
I can see two possible reasons for this error.
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.
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
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
You can start the terminal anywhere and use the mongoimport command
if the error persist the check your Environment variable and follow the steps from @Fawzy Mokhtar
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.
Download the MongoDB Database Tools from MongoDB official Website - https://www.mongodb.com/try/download/database-tools and Unzip the folder
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
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
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.
- https://www.mongodb.com/docs/database-tools/installation/installation/[enter link description here]1 use this link and download all the tool set.
- Select your platform(Linux/windows/macOS).
- For windows, Download the Database Tools using https://www.mongodb.com/try/download/shell
- then follow following instructions
- or you can easily copy below downloaded tolls
- And paste in your mongodb server bin folder
Click the Download button
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
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')
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
© 2022 - 2024 — McMap. All rights reserved.