mongodb问题:按照教程操作mongodb,但是没有找到mongo

发布时间 2023-05-17 05:14:53作者: 胡安

错误:

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 E:\Programs\mongosh> mongosh
Current Mongosh Log ID: 6463f096f1860e5538895c3b
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.8.2
Using MongoDB:          6.0.6
Using Mongosh:          1.8.2

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
   2023-05-17T04:57:24.438+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------

test>

参考

https://blog.csdn.net/SDDX_CDY/article/details/126922378