mongodb 安装

mongodb 安装

作为一个前端开发,操作数据库太过困难了,而 mongo 的操作语法就是 json,对前端非常友好,对于我这种技术水平,肯定是非常合适的。

至于 mongo 是 NoSQL(not only sql)等优点就不多做介绍了,可以今天记录一下安装 mongo 的过程和遇到的一些问题。

先去官网下载:https://www.mongodb.com/

选择社区版,具体哪个版本是最稳定,用的最多的,还真是不清楚,稳一点就选择 4.x,因为公司就在用这个版本,我直接选择最新的:

安装的时候就只需要注意几点,一个是 custom,自定义安装路径,另一个是 data directory 和 log directory,这两个是数据库的存放路径和 log 路径:



安装成功之后,浏览器访问http://localhost:27017

如果有输出:

It looks like you are trying to access MongoDB over HTTP on the native driver port.

那就是安装成功了,我选的是 7.0,默认安装了 mongodb compass,其它版本好像是可以选择是否安装,不勾选就不会(不知道是不是我没注意),mongodb compass 是一个可视化工具,也可以下载 mongo 那边的 tools 单独下载。

当我安装成功之后,命令行运行 mongo 会报错命令不存在,运行 mongod 会有一堆报错:

复制代码
{"t":{"$date":"2023-12-13T16:20:18.849+08:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"thread1","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":21},"outgoing":{"minWireVersion":6,"maxWireVersion":21},"isInternalClient":true}}}
{"t":{"$date":"2023-12-13T16:20:20.307+08:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"thread1","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2023-12-13T16:20:20.307+08:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"thread1","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2023-12-13T16:20:20.310+08:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
{"t":{"$date":"2023-12-13T16:20:20.310+08:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2023-12-13T16:20:20.310+08:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"thread1","msg":"Multi threading initialized"}
{"t":{"$date":"2023-12-13T16:20:20.310+08:00"},"s":"I",  "c":"TENANT_M", "id":7091600, "ctx":"thread1","msg":"Starting TenantMigrationAccessBlockerRegistry"}
{"t":{"$date":"2023-12-13T16:20:20.311+08:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":3772,"port":27017,"dbPath":"C:/data/db/","architecture":"64-bit","host":"Wade"}}
{"t":{"$date":"2023-12-13T16:20:20.311+08:00"},"s":"I",  "c":"CONTROL",  "id":23398,   "ctx":"initandlisten","msg":"Target operating system minimum version","attr":{"targetMinOS":"Windows 7/Windows Server 2008 R2"}}
{"t":{"$date":"2023-12-13T16:20:20.311+08:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"7.0.4","gitVersion":"38f3e37057a43d2e9f41a39142681a76062d582e","modules":[],"allocator":"tcmalloc","environment":{"distmod":"windows","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2023-12-13T16:20:20.311+08:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Microsoft Windows 10","version":"10.0 (build 22621)"}}}
{"t":{"$date":"2023-12-13T16:20:20.311+08:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2023-12-13T16:20:20.312+08:00"},"s":"E",  "c":"CONTROL",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory C:\\data\\db\\ not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}
{"t":{"$date":"2023-12-13T16:20:20.312+08:00"},"s":"I",  "c":"REPL",     "id":4784900, "ctx":"initandlisten","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":15000}}
{"t":{"$date":"2023-12-13T16:20:20.312+08:00"},"s":"I",  "c":"REPL",     "id":4794602, "ctx":"initandlisten","msg":"Attempting to enter quiesce mode"}
{"t":{"$date":"2023-12-13T16:20:20.312+08:00"},"s":"I",  "c":"-",        "id":6371601, "ctx":"initandlisten","msg":"Shutting down the FLE Crud thread pool"}
{"t":{"$date":"2023-12-13T16:20:20.312+08:00"},"s":"I",  "c":"COMMAND",  "id":4784901, "ctx":"initandlisten","msg":"Shutting down the MirrorMaestro"}
{"t":{"$date":"2023-12-13T16:20:20.312+08:00"},"s":"I",  "c":"SHARDING", "id":4784902, "ctx":"initandlisten","msg":"Shutting down the WaitForMajorityService"}
{"t":{"$date":"2023-12-13T16:20:20.312+08:00"},"s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2023-12-13T16:20:20.312+08:00"},"s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"initandlisten","msg":"Shutting down the global connection pool"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"CONTROL",  "id":4784906, "ctx":"initandlisten","msg":"Shutting down the FlowControlTicketholder"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"NETWORK",  "id":4784918, "ctx":"initandlisten","msg":"Shutting down the ReplicaSetMonitor"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"SHARDING", "id":4784921, "ctx":"initandlisten","msg":"Shutting down the MigrationUtilExecutor"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"ASIO",     "id":22582,   "ctx":"MigrationUtil-TaskExecutor","msg":"Killing all outstanding egress activity."}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"COMMAND",  "id":4784923, "ctx":"initandlisten","msg":"Shutting down the ServiceEntryPoint"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"CONTROL",  "id":4784928, "ctx":"initandlisten","msg":"Shutting down the TTL monitor"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"CONTROL",  "id":6278511, "ctx":"initandlisten","msg":"Shutting down the Change Stream Expired Pre-images Remover"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"CONTROL",  "id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"-",        "id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2023-12-13T16:20:20.313+08:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}

然后就说是 dbpath 没配置对:

复制代码
{"error":"NonExistentPath: Data directory C:\\data\\db\\ not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}

但是 mongod.cfg 里面配置的是有的,就一顿折腾,各种指定 dbpath 和新建 data/db,和配置 mongod 系统路径,但是用浏览器看是启动了,可视化工具也能连接:

最后发现 MongoDB 是从 MongoDB 5.0 版本开始在命令行环境使用 mongosh 命令来控制和操作 MongoDB 的。是在这个地址找到的,提到了这一点,且,没有专门配置环境变量:
https://www.alibabacloud.com/help/zh/mongodb/product-overview/features-of-mongodb-5-0

在早期的 MongoDB 版本中,通常使用 mongo 或者 mongod 命令,所以在下载 mongo 的地方选择 tools,下载安装 mongosh:


admin/config/local 是默认就有的,每一个相当于 MySQL 的数据库,里面新建 Collection 相当于 MySQL 的表。

至此,mongodb 安装完成,就可以开始自己本地开始随便学习了。

欢迎关注订阅号 coding 个人笔记

相关推荐
王柏龙6 分钟前
Entity Framework Core (EF Core) 中Database
数据库·microsoft
时序数据说10 分钟前
时序数据库IoTDB的优势场景分析
大数据·数据库·物联网·时序数据库·iotdb
是阿建吖!23 分钟前
【Redis】初识Redis(定义、特征、使用场景)
数据库·redis·缓存
Leo.yuan24 分钟前
数据处理工具是做什么的?常见数据处理方法介绍
大数据·数据库·人工智能·python·信息可视化
旧时光巷33 分钟前
SQL基础⑫ | 视图篇
数据库·sql·学习·mysql·oracle·视图
阿里云大数据AI技术1 小时前
[VLDB 2025]面向云计算平台的多模态慢查询根因排序
大数据·数据库·人工智能
WJ.Polar2 小时前
Python与Mysql
开发语言·数据库·python·mysql
ssjnbnbnb2 小时前
数据库概述(学习笔记)
数据库·笔记·学习
是店小二呀2 小时前
AI时代的数据库革命:电科金仓的“融合+AI“战略解析
数据库·人工智能·oracle
JSON_L3 小时前
Laravel 分页方案整理
数据库·php·laravel