问题:
在terminal中, 输入命令mongoimport, 将JSON文件内容导入mongoDB数据库.
mongo-demo $ mongoimport --db mongo-exesices --collection courses --drop --file exesice-data.json --jsonArray
-bash: mongoimport: command not found
解决:
一. 官网文档查询: https://docs.mongodb.com
Starting with MongoDB 4.4, the MongoDB Database Tools are now released separately from the MongoDB Server and use their own versioning, with an initial version of 100.0.0. Previously, these tools were released alongside the MongoDB Server and used matching versioning.
原来从MongoDB 4.4开始, 原本随同MongoDB Server一起发行的MongoDB 数据库工具, 将单独发行了.
二. 安装MongoDB Database Tools 数据库工具
-
Install Homebrew.¶
macOS does not include the Homebrew
brew
package by default. Installbrew
using the official Homebrew installation instructions. -
In your macOS Terminal, run the following command to download the official MongoDB Homebrew formulae for MongoDB and the Database Tools:
brew tap mongodb/brew
-
Install the MongoDB Database Tools.
In your macOS Terminal, run the following command to install the MongoDB Database Tools:
brew install mongodb-database-tools
Tip: Once installed, you can later update the Database Tools with:
brew upgrade mongodb-database-tools
-
Once installed, you can run any of the Database Tools directly from your macOS Terminal. Consult the reference page for the specific tool you wish to use for its full syntax and usage.
ENJOY!
mongo-demo $ mongoimport
-bash: mongoimport: command not found
mongo-demo $ brew install mongodb-database-tools
==> Installing mongodb-database-tools from mongodb/brew
==> Downloading https://fastdl.mongodb.org/tools/db/mongodb-database-tools-macos-x86_64-100.3.1.zip
######################################################################## 100.0%
🍺 /usr/local/Cellar/mongodb-database-tools/100.3.1: 13 files, 150.9MB, built in 5 seconds
mongo-demo $ mongoimport --db mongo-exesices --collection courses --drop --file exesice-data.json --jsonArray
2021-07-09T02:10:04.290+0800 connected to: mongodb://localhost/
2021-07-09T02:10:04.291+0800 dropping: mongo-exesices.courses
2021-07-09T02:10:04.435+0800 7 document(s) imported successfully. 0 document(s) failed to import.