MongoDB 不在开源了,使用 Homebrew 安装只能玩社区版了
使用了大半年的 mongodb ,最近在公司的新项目中应用,在 mac 上安装 mongodb 时发现始终安装不了,一直在报下面这样的错误:
brew install mongodb

升级 brew 也不行,这个 mac 机上从未安装过 mongodb,但从错误信息中提示却是要卸载它,真是醉了。
从2019年9月2日开始 ,HomeBrew 也从核心仓库 (#43770) 当中移除了mongodb 模块
不过,幸运的是 mongodb 团队还在维护社区版的 Homebrew,最后还是从Stack Overflow 上查找到答案:

为了搞清楚这些是啥意思,查看了 homebrew-brew gitHub。
- 在安装社区版前要先执行:brew tap mongodb/brew 这个过程有点久,我装过可能需要30分钟左右。
- 安装最新社区版:brew reinstall mongodb-community
- 启动 mongodb-community 服务:
brew services start mongodb-community ,提示 “Service `mongodb-community` already started”,说明服务启动成功
mongodb-community 命令区别 mongodb
- 启动服务:brew services start mongodb-community
- 重启服务: brew services restart mongodb-community
- 停止服务:brew services stop mongodb-community
- 安装某个版本:brew install mongodb-community@x.x.x
- 手动启动服务:mongod --config /usr/local/etc/mongod.conf
文件路径:
-
配置文件:/usr/local/etc/mongod.conf 日志目录路径:/usr/local/var/log/mongodb数据目录路径:/usr/local/var/mongodb
这样 MongoDB 服务就安装和启动好了。
将 MongoDB 下载到本地,mongodb-osx-ssl-x86_64-4.0.13.tgz 我下载的是这个版本,解压后,新建目录,将解压后的文件存放在里面。
我的目录为:/Volumes/code/localhost/node/mongodb/bin
- 创建存储数据库文件
data
在任意盘符根目录下创建一个 data 目录,用来存放数据库文件。 mongoDB 会自动把自己安装位置的盘符根目录下的 data 文件夹作为自己的数据存储目录,这里也可以直接在安装位置所在盘符创建,我是在 bin 目录下创建的 data 目录。
新开一个 shell,指定 db 路径:
进入 /Volumes/code/localhost/node/mongodb/bin 目录 ,输入 mongod,会看到 :
MongoDB starting : pid=942 port=27017 dbpath=/data/db 64-bit
db version v4.2.1
git version: edf6d45851c0b9ee15548f0f847df141764a317e
。。。
说明 db 启动成功了!!
如果 data 目录在其它位置,需要指定 data 目录路径,输入 mongod --dbpath 路径
- 连接数据库 npm run start
在 server.js 中,进行配置:
const mongoose = require('mongoose');
const mongoClient = require('mongodb').MongoClient;
// db
const dburl = "mongodb://127.0.0.1:27017/local";
mongoClient.connect(dburl, (err, db) => {
if (err) {
console.log('数据库连接失败!');
return;
};
console.log(db);
});
在 package.json 中,进行配置:
"scripts": {
"server": "node server.js",
"start": "nodemon server.js"
},
const dburl = "mongodb://127.0.0.1:27017/local";
默认情况下,db 启动成功后,本地会有三个表 admin / config / local
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
>
- 查看 db 配置信息 npm run start ,成功的启动 服务并连接 db
> web@1.0.0 start /Volumes/code/localhost/node/web
> nodemon server.js [nodemon] 1.19.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
(node:1009) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Successful! 访问地址为 http://127.0.0.1:3000
MongoClient {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
s: {
url: 'mongodb://127.0.0.1:27017/local',
options: {
servers: [Array],
caseTranslate: true,
dbName: 'local',
socketTimeoutMS: 360000,
connectTimeoutMS: 30000,
retryWrites: true,
useRecoveryToken: true,
readPreference: [ReadPreference],
promiseLibrary: [Function: Promise]
},
promiseLibrary: [Function: Promise],
dbCache: Map {},
sessions: Set {},
writeConcern: undefined,
namespace: MongoDBNamespace { db: 'admin', collection: undefined }
},
topology: Server {
_events: [Object: null prototype] {
serverOpening: [Function],
serverDescriptionChanged: [Function],
serverHeartbeatStarted: [Function],
serverHeartbeatSucceeded: [Function],
serverHeartbeatFailed: [Function],
serverClosed: [Function],
topologyOpening: [Function],
topologyClosed: [Function],
topologyDescriptionChanged: [Function],
commandStarted: [Function],
commandSucceeded: [Function],
commandFailed: [Function],
joined: [Function],
left: [Function],
ping: [Function],
ha: [Function],
authenticated: [Function],
error: [Function],
timeout: [Function],
close: [Function],
parseError: [Function],
open: [Function],
fullsetup: [Function],
all: [Function],
reconnect: [Function]
},
_eventsCount: 25,
_maxListeners: Infinity,
clientInfo: {
driver: [Object],
os: [Object],
platform: 'Node.js v12.11.1, LE'
},
s: {
coreTopology: [Server],
sCapabilities: null,
clonedOptions: [Object],
reconnect: true,
emitError: true,
poolSize: 5,
storeOptions: [Object],
store: [Store],
host: '127.0.0.1',
port: 27017,
options: [Object],
sessionPool: [ServerSessionPool],
sessions: Set {},
promiseLibrary: [Function: Promise]
}
}
}
MongoDB 不在开源了,使用 Homebrew 安装只能玩社区版了的更多相关文章
- centos 7 安装 Docker Engine-CentOS 社区版
获取Docker Engine-CentOS社区: https://docs.docker.com/install/linux/docker-ce/centos/ 1.操作系统要求 1.1 要安装 D ...
- 安装蓝鲸paas社区版
安装蓝鲸paas社区版http://docs.bk.tencent.com/bkce_install_guide/setup/get_ready.html#hostssystemctl stop fi ...
- Ubuntu 安装 Docker CE(社区版)
参考自 https://yeasy.gitbooks.io/docker_practice/install/ubuntu.html#ubuntu-1604- docker-io 是以前早期的版本,版本 ...
- CentOS 7安装Odoo 15社区版的详细操作指南
我之前的文章介绍过在Windows环境下安装Odoo 15,如果您需要在Windows部署,具体可参考我文末的微信号<10分钟教你本机电脑安装Odoo 15,并启用一个内置的项目APP应用> ...
- Docker 镜像安装 GitLab 中文社区版
docker run \ --detach \ --publish : \ --publish : \ --name gitlab \ --restart unless-stopped \ --vol ...
- docker 安装 gitlab 中文社区版
docker pull twang2218/gitlab-ce-zh 创建一个docker 目录 /usr/local/docker/gitlab 创建一个 docker-compose.yml ve ...
- Docker(社区版) centos版 安装
1,总结一下docker的安装,其实官网有很全面的资料了,可以自己上面去看,但都是英文的. https://docs.docker.com/engine/installation/linux/dock ...
- Mac OSX 下用 Homebrew 安装 MongoDB 并配置到 WebStorm 中
1. 安装 Ruby OSX 操作系统内置 Ruby,但如果没有 Ruby,则需先输入以下命令安装能够进行多版本ruby环境安装.管理和切换的命令行工具 RVM. 1.1 安装 RVM 打开终端输入以 ...
- HomeBrew安装MongoDB如何启动
1.先安装HomeBrew 安装(需要 Ruby): ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/in ...
随机推荐
- 第421期 Python 周刊
新闻 感谢 Guido 链接: https://blog.dropbox.com/topics/company/thank-you--guido Python之父 Guido van Rossum 即 ...
- 爬虫(四):requests模块
1. requests模块 1.1 requests简介 requests 是一个功能强大.简单易用的 HTTP 请求库,比起之前用到的urllib模块,requests模块的api更加便捷.(本质就 ...
- springboot + springcloud +nacos实战
首先从整个软件的功能和应用场景来说,nacos更像consul,而非eureka,nacos设计的时候自带的配置中心功能,让我们省下了去搞springcloud config的时间,但这里并不是说na ...
- IS Kali: installed chiess messy code problem
apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy init 6
- 2、netty第一个例子,简单的http服务器
用netty来启动一个简单的可处理http请求的服务器. 依照前面写的使用netty的过程.贴上代码 server import io.netty.bootstrap.ServerBootstrap; ...
- Redhat Linx使用Centos yum源
一.故障现象: 在安装了Read linux后,使用yum安装软件,出现如下提示:[root@localhost~]# yum install xxxLoaded plugins: product-i ...
- s3c2440裸机-代码重定位、清bss的改进和位置无关码
1.代码重定位的改进 用ldr.str代替ldrb, strb加快代码重定位的速度. 前面重定位时,我们使用的是ldrb命令从的Nor Flash读取1字节数据,再用strb命令将1字节数据写到SDR ...
- Linux下安装Redis以及遇到的问题
参考链接:https://www.cnblogs.com/zdd-java/p/10288734.html https://www.cnblogs.com/uncleyong/p/9882843.ht ...
- IntersectionObserver API,观察元素是否进入了可视区域
网页开发时,常常需要了解某个元素是否进入了"视口"(viewport),即用户能不能看到它. 上图的绿色方块不断滚动,顶部会提示它的可见性. 传统的实现方法是,监听到scroll事 ...
- BZOJ2301/LG2522 「HAOI2011」Problem B 莫比乌斯反演 数论分块
问题描述 BZOJ2301 LG2522 积性函数 若函数 \(f(x)\) 满足对于任意两个最大公约数为 \(1\) 的数 \(m,n\) ,有 \(f(mn)=f(m) \times f(n)\) ...