mongodb正常安装后,修改环境变量,且mongod能轻松跑同,但是mongo命令无法被正确执行,回显如下:

mongo : 无法将“mongo”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正
确,然后再试一次。
所在位置 行:1 字符: 1
+ mongo
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (mongo:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

前往安装目录下/bin目录中,没有mongo.exe文件,只有mongod和mongos,以及一个powershell命令脚本。

原因在于,mongodb6.0以后做出了重大改变,mongodb已经不再默认为你安装shell工具,因此需要安装一个额外的shell:Install mongosh — MongoDB Shell,这个工具被称为mongosh

前往mongoshell页面下载mongoshell,以后就用mongosh连接这个就好了。

记得把mongosh的安装目录也添加到环境变量,然后连接mongosh就好了。

PS C:\Windows\system32> mongosh
Current Mongosh Log ID: 63270cf93e2cd7827dabb1f7
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.4
Using MongoDB:          6.0.1
Using Mongosh:          1.5.4

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

------
   The server generated these startup warnings when booting
   2022-09-18T20:19:33.889+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------

------
   Enable MongoDB's free cloud-based monitoring service, which will then receive and display
   metrics about your deployment (disk utilization, CPU, operation statistics, etc).

   The monitoring data will be available on a MongoDB website with a unique URL accessible to you
   and anyone you share the URL with. MongoDB may use this information to make product
   improvements and to suggest MongoDB products and deployment options to you.

   To enable free monitoring, run the following command: db.enableFreeMonitoring()
   To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
------

test> show dbs
admin   40.00 KiB
config  12.00 KiB
local   40.00 KiB
test>

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐