Whidy Writes

MacOS 10.15.x 通过Homebrew安装mongoDB

创建于:最后更新:whidy

今天更新系统 Hombrew 时候,突然发现本地的 mongoDB 不能用了,好像是版本不兼容还是 tap 中移除了 mongoDB ,难道自从升级到 10.15.x 后, mongoDB 就坏了,比较少用到,所以才发现。升级安装竟然折腾了一些时间,现在就总结一下吧。

全新安装

如果第一次安装这个真的就不会有什么问题了,直接采用官方的安装方法即可。

全新安装目前最新版本 mongodb-community@4.4 ,依次运行如下命令:

brew tap mongodb/brew
brew install mongodb-community@4.4

启动服务

brew services start mongodb-community@4.4

测试安装效果

mongo

会输出如下信息

MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
...
>

就OK了,如果还需要开机启动,后台运行,具体可以看看官方说明。

升级安装

这个就比较坑了。花了好多时间去研究哪里出了问题。

同样是brew移除旧版,并安装新版(4.4)的操作,但是需要注意的是,如果旧版低于 4.2 那么数据库可能会不兼容。首先,可能需要查看一下旧版的brew相关配置,如下是我的:

  • /Users/whidy/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist (服务启动根据这个配置)
  • /usr/local/etc/mongod.conf (这个文件是上面文件中找到的,启动时使用的mongod配置)

从第二个文件中可以看到,旧的 storage 下的 dbPath/usr/local/var/mongodb ,也就是原来的数据存储目录,在你升级4.4版后,这些配置不会变更。

然后通过 brew services 来查看服务启动情况, status 那一列确是黄色started ,一般来说非绿色都是有问题的。但是目前又不知道哪里除了问题,暂时先不管这个。

终端中执行 mongo ,却始终无法成功。提示的错误信息并无参考价值,如下:

MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:362:17
@(connect):2:6
exception: connect failed
exiting with code 1

起初以为是服务问题(毕竟黄色看起来就是有问题),反复查找相关日志,看为什么服务是黄色。直到后来...

因为mongo无法启动、brew服务又是非正常,于是直接停掉服务 brew services stop mongodb-community ,直接采用 mongod 尝试启动服务,来查看问题,得到如下结果:

{"t":{"$date":"2020-09-22T14:54:01.367+08:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2020-09-22T14:54:01.371+08:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-22T14:54:01.371+08:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-09-22T14:54:01.371+08:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":23135,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"Macbook.local"}}
{"t":{"$date":"2020-09-22T14:54:01.371+08:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-09-22T14:54:01.410+08:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"19.6.0"}}}
{"t":{"$date":"2020-09-22T14:54:01.410+08:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2020-09-22T14:54:01.414+08:00"},"s":"E",  "c":"STORAGE",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory /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":"2020-09-22T14:54:01.414+08:00"},"s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2020-09-22T14:54:01.414+08:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."}
{"t":{"$date":"2020-09-22T14:54:01.418+08:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2020-09-22T14:54:01.418+08:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}

这么大一段,粗略看了下,需要关注的地方是 {"error":"NonExistentPath: Data directory /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 --dbpath /usr/local/var/mongodb

这个路径是旧的数据文件存放目录,又得到如下信息:

{"t":{"$date":"2020-09-22T14:59:40.883+08:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2020-09-22T14:59:40.885+08:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-22T14:59:40.885+08:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-09-22T14:59:40.886+08:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":23535,"port":27017,"dbPath":"/usr/local/var/mongodb","architecture":"64-bit","host":"Macbook.local"}}
{"t":{"$date":"2020-09-22T14:59:40.886+08:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-09-22T14:59:40.919+08:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"19.6.0"}}}
{"t":{"$date":"2020-09-22T14:59:40.919+08:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"storage":{"dbPath":"/usr/local/var/mongodb"}}}}
{"t":{"$date":"2020-09-22T14:59:40.920+08:00"},"s":"I",  "c":"STORAGE",  "id":22270,   "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"/usr/local/var/mongodb","storageEngine":"wiredTiger"}}
{"t":{"$date":"2020-09-22T14:59:40.921+08:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=7680M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
{"t":{"$date":"2020-09-22T14:59:41.374+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757981:374228][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 116 through 117"}}
{"t":{"$date":"2020-09-22T14:59:41.430+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757981:430036][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 117 through 117"}}
{"t":{"$date":"2020-09-22T14:59:41.490+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757981:490321][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Main recovery loop: starting at 116/1792 to 117/256"}}
{"t":{"$date":"2020-09-22T14:59:41.570+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757981:570122][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 116 through 117"}}
{"t":{"$date":"2020-09-22T14:59:41.627+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757981:627819][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 117 through 117"}}
{"t":{"$date":"2020-09-22T14:59:41.667+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757981:667625][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global recovery timestamp: (0, 0)"}}
{"t":{"$date":"2020-09-22T14:59:41.717+08:00"},"s":"I",  "c":"STORAGE",  "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":796}}
{"t":{"$date":"2020-09-22T14:59:41.717+08:00"},"s":"I",  "c":"RECOVERY", "id":23987,   "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}
{"t":{"$date":"2020-09-22T14:59:41.725+08:00"},"s":"I",  "c":"STORAGE",  "id":22262,   "ctx":"initandlisten","msg":"Timestamp monitor starting"}
{"t":{"$date":"2020-09-22T14:59:41.726+08:00"},"s":"W",  "c":"CONTROL",  "id":22120,   "ctx":"initandlisten","msg":"Access control is not enabled for the database. Read and write access to data and configuration is unrestricted","tags":["startupWarnings"]}
{"t":{"$date":"2020-09-22T14:59:41.741+08:00"},"s":"W",  "c":"CONTROL",  "id":22140,   "ctx":"initandlisten","msg":"This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning","tags":["startupWarnings"]}
{"t":{"$date":"2020-09-22T14:59:41.741+08:00"},"s":"W",  "c":"CONTROL",  "id":22184,   "ctx":"initandlisten","msg":"Soft rlimits too low","attr":{"currentValue":8192,"recommendedMinimum":64000},"tags":["startupWarnings"]}
{"t":{"$date":"2020-09-22T14:59:41.763+08:00"},"s":"F",  "c":"CONTROL",  "id":20573,   "ctx":"initandlisten","msg":"Wrong mongod version","attr":{"error":"UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document (ERROR: BadValue: Invalid value for version, found 4.0, expected '4.4' or '4.2'. Contents of featureCompatibilityVersion document in admin.system.version: { _id: \"featureCompatibilityVersion\", version: \"4.0\" }. See https://docs.mongodb.com/master/release-notes/4.4-compatibility/#feature-compatibility.). If the current featureCompatibilityVersion is below 4.2, see the documentation on upgrading at https://docs.mongodb.com/master/release-notes/4.4/#upgrade-procedures."}}
{"t":{"$date":"2020-09-22T14:59:41.763+08:00"},"s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2020-09-22T14:59:41.763+08:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."}
{"t":{"$date":"2020-09-22T14:59:41.824+08:00"},"s":"I",  "c":"-",        "id":4695300, "ctx":"initandlisten","msg":"Interrupted all currently running operations","attr":{"opsKilled":3}}
{"t":{"$date":"2020-09-22T14:59:41.824+08:00"},"s":"I",  "c":"STORAGE",  "id":20282,   "ctx":"initandlisten","msg":"Deregistering all the collections"}
{"t":{"$date":"2020-09-22T14:59:41.824+08:00"},"s":"I",  "c":"STORAGE",  "id":22261,   "ctx":"initandlisten","msg":"Timestamp monitor shutting down"}
{"t":{"$date":"2020-09-22T14:59:41.824+08:00"},"s":"I",  "c":"STORAGE",  "id":22317,   "ctx":"initandlisten","msg":"WiredTigerKVEngine shutting down"}
{"t":{"$date":"2020-09-22T14:59:41.824+08:00"},"s":"I",  "c":"STORAGE",  "id":22318,   "ctx":"initandlisten","msg":"Shutting down session sweeper thread"}
{"t":{"$date":"2020-09-22T14:59:41.824+08:00"},"s":"I",  "c":"STORAGE",  "id":22319,   "ctx":"initandlisten","msg":"Finished shutting down session sweeper thread"}
{"t":{"$date":"2020-09-22T14:59:41.824+08:00"},"s":"I",  "c":"STORAGE",  "id":22320,   "ctx":"initandlisten","msg":"Shutting down journal flusher thread"}
{"t":{"$date":"2020-09-22T14:59:41.832+08:00"},"s":"I",  "c":"STORAGE",  "id":22321,   "ctx":"initandlisten","msg":"Finished shutting down journal flusher thread"}
{"t":{"$date":"2020-09-22T14:59:41.832+08:00"},"s":"I",  "c":"STORAGE",  "id":22322,   "ctx":"initandlisten","msg":"Shutting down checkpoint thread"}
{"t":{"$date":"2020-09-22T14:59:41.833+08:00"},"s":"I",  "c":"STORAGE",  "id":22323,   "ctx":"initandlisten","msg":"Finished shutting down checkpoint thread"}
{"t":{"$date":"2020-09-22T14:59:41.833+08:00"},"s":"I",  "c":"STORAGE",  "id":22324,   "ctx":"initandlisten","msg":"Closing WiredTiger in preparation for reconfiguring","attr":{"closeConfig":"leak_memory=true,"}}
{"t":{"$date":"2020-09-22T14:59:41.869+08:00"},"s":"I",  "c":"STORAGE",  "id":4795905, "ctx":"initandlisten","msg":"WiredTiger closed","attr":{"durationMillis":36}}
{"t":{"$date":"2020-09-22T14:59:41.911+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757981:911775][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 117 through 118"}}
{"t":{"$date":"2020-09-22T14:59:41.967+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757981:967751][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 118 through 118"}}
{"t":{"$date":"2020-09-22T14:59:42.026+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757982:26293][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Main recovery loop: starting at 117/896 to 118/256"}}
{"t":{"$date":"2020-09-22T14:59:42.111+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757982:111712][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 117 through 118"}}
{"t":{"$date":"2020-09-22T14:59:42.171+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757982:171263][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 118 through 118"}}
{"t":{"$date":"2020-09-22T14:59:42.209+08:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1600757982:209013][23535:0x11d455dc0], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global recovery timestamp: (0, 0)"}}
{"t":{"$date":"2020-09-22T14:59:42.258+08:00"},"s":"I",  "c":"STORAGE",  "id":4795904, "ctx":"initandlisten","msg":"WiredTiger re-opened","attr":{"durationMillis":389}}
{"t":{"$date":"2020-09-22T14:59:42.258+08:00"},"s":"I",  "c":"STORAGE",  "id":22325,   "ctx":"initandlisten","msg":"Reconfiguring","attr":{"newConfig":"compatibility=(release=3.3)"}}
{"t":{"$date":"2020-09-22T14:59:42.368+08:00"},"s":"I",  "c":"STORAGE",  "id":4795903, "ctx":"initandlisten","msg":"Reconfigure complete","attr":{"durationMillis":110}}
{"t":{"$date":"2020-09-22T14:59:42.368+08:00"},"s":"I",  "c":"STORAGE",  "id":4795902, "ctx":"initandlisten","msg":"Closing WiredTiger","attr":{"closeConfig":"leak_memory=true,"}}
{"t":{"$date":"2020-09-22T14:59:42.411+08:00"},"s":"I",  "c":"STORAGE",  "id":4795901, "ctx":"initandlisten","msg":"WiredTiger closed","attr":{"durationMillis":43}}
{"t":{"$date":"2020-09-22T14:59:42.411+08:00"},"s":"I",  "c":"STORAGE",  "id":22279,   "ctx":"initandlisten","msg":"shutdown: removing fs lock..."}
{"t":{"$date":"2020-09-22T14:59:42.412+08:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2020-09-22T14:59:42.412+08:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":62}}

这可真是很长的一段,找到关键信息:

{"error":"UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document (ERROR: BadValue: Invalid value for version, found 4.0, expected '4.4' or '4.2'. Contents of featureCompatibilityVersion document in admin.system.version: { _id: \"featureCompatibilityVersion\", version: \"4.0\" }. See https://docs.mongodb.com/master/release-notes/4.4-compatibility/#feature-compatibility.). If the current featureCompatibilityVersion is below 4.2, see the documentation on upgrading at https://docs.mongodb.com/master/release-notes/4.4/#upgrade-procedures."}

大致意思是,新版的mongodb的默认数据库admin,里面的value不正确,大概之前旧版用的是 4.0 。而仅支持的值应该是 4.2 或者是 4.4 。目前依然无法启动mongo服务,于是我就只能新建一个对应新版mongodb的目录 /Users/whidy/data/db ,再次运行命令:

mongod --dbpath /Users/whidy/data/db

这下服务倒是启动成功了,可是旧版的数据库咋办。

升级解决方案一:不要用最新版,用4.2版

本次因为旧版是4.0,那最省事的操作方法就是直接用4.2,不要跨版本升级。也是最省事的办法,简单说明下操作:

  1. 删除最新版(4.4): brew remove mongodb-community
  2. 安装4.2版: brew install mongodb-community@4.2
  3. 重启服务: brew services start mongodb-community@4.2 这就完事了。可以通过 brew services 看到,服务状态也是绿色 started 了,很舒服。

这个是相对推荐的,简单且快速。

升级解决方案二:备份数据,升级后还原数据

备份有多种,这里仅介绍整个mongodb备份和某个db备份,都是使用 mongodump 命令,本地操作。

  • 【推荐】备份完整MongoDB的所有数据: mongodump --host 127.0.0.1 --port 27017 --out /Users/whidy/backup-mongodb
  • 备份某个DB(假设数据库名为 test ): mongodump --db test --out /Users/whidy/backup-mongodb-test 备份完成后,删除现有的 mongodb-community@4.2 (或者其它更旧的版本):
brew remove mongodb-community@4.2

安装最新版,跟上面全新安装相同:

brew install mongodb-community

修改文件 /usr/local/etc/mongod.conf 中的 dbPath 为新创建的地址 /Users/whidy/data/db ,重启服务看看效果:

brew services restart mongodb-community

通过 brew services 看到状态还是黄色的started不用管。

执行 mongo ,成功连接上了,并返回了操作终端,大致信息如下:

MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0da177c6-1bf3-494a-b0f3-feeda3a16a82") }
MongoDB server version: 4.4.0
---
The server generated these startup warnings when booting:
        2020-09-22T16:19:50.689+08:00: ***** SERVER RESTARTED *****
        2020-09-22T16:19:51.828+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2020-09-22T16:19:51.829+08:00: Soft rlimits too low
        2020-09-22T16:19:51.829+08:00:         currentValue: 256
        2020-09-22T16:19:51.829+08:00:         recommendedMinimum: 64000
---
---
        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()
---
>

我们看下现有数据库 show dbs ,应该只有三个,分别是 adminconfiglocal

接下来进行还原操作:

mongorestore /Users/whidy/backup-mongodb/

一般来说应该是挺顺利的。完成后,再次重启服务 brew services restart mongodb-community ,并进入 mongo ,执行 show dbs ,可以看到原来的数据了。

截至目前一切完成。终于折腾完了。

不过还是有个问题为什么brew services下的mongo服务状态是绿色的,日志后来发现在这里 /usr/local/var/log/mongodb/mongo.log ,最主要的是,这里也没有提示错误信息,真实奇怪害!

其它内容:

avatar

Whidy

一名爱折腾的前端开发工程师,喜欢玩游戏听歌写东西 ฅʕ•̫͡•ʔฅ