【mongodb 基础2】Install MongoDB Community Edition on macOS

article/2024/3/2 10:17:46

文章目录

  • 一. 安装准备
    • Install Xcode Command-Line Tools
    • Install Homebrew
  • 二. Installing MongoDB 6.0 Community Edition
    • 1. 下载MongoDB Homebrew 组件包
    • 2. 更新组件包
    • 3. 安装MongoDBTo install MongoDB
  • 三. 安装后包含的组件
  • 四. Run&stop MongoDB
    • 1. 作为macOS服务的方式运行mongodb
    • 2. stop mongod
    • 3. verify that MongoDB is running
    • 4. the log file
  • 五. Connect and Use MongoDB
    • 1. Connect MongoDB
    • 2. other tools
    • 3. default setting

本文参考官网通过Homebrew安装MongoDB
 
Use this tutorial to install MongoDB 6.0 Community Edition on macOS using the third-party Homebrew package manager.

 

一. 安装准备

Install Xcode Command-Line Tools

Install the Xcode command-line tools by running the following command in your macOS Terminal:

xcode-select --install

 

Install Homebrew

macOS does not include the Homebrew brew package by default.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

brew官网:https://brew.sh/#install

 

二. Installing MongoDB 6.0 Community Edition

1. 下载MongoDB Homebrew 组件包

Tap the MongoDB Homebrew Tap to download the official Homebrew formula for MongoDB and the Database Tools,

brew tap mongodb/brew

 

2. 更新组件包

To update Homebrew and all existing formulae:

brew update

 

3. 安装MongoDBTo install MongoDB

brew install mongodb-community@6.0

 

可能出现的问题

Error: Command failed with exit 128: git

执行:brew -v

lianggao@LiangdeMacBook-Pro ~ % brew -v
Homebrew 4.0.6
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)

根据提示添加:

lianggao@LiangdeMacBook-Pro ~ % git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core  
lianggao@LiangdeMacBook-Pro ~ % git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

 

三. 安装后包含的组件

The installation includes the following binaries:

  • The mongod server
  • The mongos sharded cluster query router
  • The MongoDB Shell, mongosh

 
创建的目录和文件

安装位置:
check where brew has installed these files and directories:

 % brew --prefix                     
/usr/local

In addition, the installation creates the following files and directories at the location specified below, depending on your Apple hardware:

在这里插入图片描述
 
 

四. Run&stop MongoDB

两种方式运行mongodb

You can run MongoDB as a macOS service using brew, or you can run MongoDB manually as a background process.

1. 作为macOS服务的方式运行mongodb

It is recommended to run MongoDB as a macOS service, as doing so sets the correct system ulimit values automatically (see ulimit settings for more information).
 
To run MongoDB (i.e. the mongod process) as a macOS service, run:

brew services start mongodb-community@6.0。。。
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-commu

 

2. stop mongod

To stop a mongod running as a macOS service, use the following command as needed:

brew services stop mongodb-community@6.0

 

3. verify that MongoDB is running

To verify that MongoDB is running, perform one of the following: If
you started MongoDB as a macOS service:

brew services list

4. the log file

You can also view the log file to see the current status of your mongod process:

/usr/local/var/log/mongodb/mongo.log.

 
 

五. Connect and Use MongoDB

1. Connect MongoDB

To begin using MongoDB, connect mongosh to the running instance.

lianggao@LiangdeMacBook-Pro ~ % mongoshlianggao@LiangdeMacBook-Pro ~ % mongosh
Current Mongosh Log ID:        641168ac9149fea4d2578ae1
Connecting to:                mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.8.0
Using MongoDB:                6.0.5
Using Mongosh:                1.8.0。。。test> 

 

2. other tools

including data backup and import/export tools like mongoimport and mongodump as well as monitoring tools like mongotop.

% mongotop

It should start up, connect to your running mongod, and start reporting usage statistics.

3. default setting

mongoDB默认绑定的ip是127.0.0.1,也就是说所有的请求只能来自本地一个节点。

By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface. This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a valid network interface.

通过设置ip来允许与外界的通讯

This value can be configured either:

  • in the MongoDB configuration file with bindIp,
  • via the command-line argument --bind_ip
     

For more information on configuring bindIp, see IP Binding.


http://www.ngui.cc/article/show-1007563.html

相关文章

计算机二级考试(C++)复习

文章目录基础知识部分C知识点部分C流操作基础知识部分 指令周期: 一般把计算机完成一条指令所花费的时间称为一个指令周期。指令周期越短,指令执行就越快。 顺序程序: 顺序程序具有顺序性、封闭性和可再现性的特点,使得程序设…

用 Java 演奏千千阙歌是什么体验?

JFugue简介 ​JFugue 是一个开放源代码编程库,它允许人们使用 Java 编程语言来编程音乐,而无需 MIDI 的复杂性。它由 David Koelle 于 2002 年首次发布。当前版本是 JFugue 5.0,已于 2015 年 3 月发布。Brian Eubanks 将 JFugue 描述为 “对于…

一个看起来非常科幻的人脸识别接口与其实现逻辑,用于二次开发

前言看起来非常高端的人脸识别接口,简单的进行二次开发就可以衍生为人脸识别考勤系统、人脸识别安全系统等等;展厅以及实现逻辑启动界面点击“是”:人脸已经录入数据库,识别失败弹出Warning可能因为误判,重新识别&…

Unity即时战略/塔防项目实战(一)——构造网格建造系统

Unity即时战略/塔防项目实战(一)—— 构造网格建造系统 效果展示 Unity RTS游戏网格建造系统实现原理 地形和格子划分,建造系统BuildManager构建 地形最终需要划分成一个一个的小方格,首先定义一下小方格: private…

2022(一等奖)D678基于改进结构函数法的大气气溶胶遥感反演

作品介绍 1 应用背景 大气气溶胶是大气中重要的成分之一,是悬浮于大气中的固体和液体微粒与它们的气体载体共同组成的多相体系,其尺度大约在10-3到102 μm之间。大气气溶胶的特性对空气质量具有良好的指示作用,气溶胶的研究对空气质量的监测…

北邮22信通:(7)实验1 题目四:一元多项式(节省内存版)

北邮22信通一枚~ 跟随课程进度每周更新数据结构与算法的代码和文章 持续关注作者 解锁更多邮苑信通专属代码~ 上一篇文章: 北邮22信通:(6)实验1 题目三 :通讯录管理_青山如墨雨如画的博客-CSDN博客 下一篇文…

pyhton第九天作业

目录 (最大数的出现)编写程序读取整数,找出它们中的最大值,然后计算它的出现次数。假设输入以数字0 结束。假设你输入的是“3 5 2 5 5 50”;序找出的最大数是而 的出现次数是4(提示:维护两个变量 max和count。变量 max 存储的是当前最大数,而…

C++语法(11)---- 模拟实现list

1.基础元素 struct list_node {list_node* _next;list_node* _prev;T _data;list_node(const T& x): _next(nullptr), _prev(nullptr), _data(x){} }; list链表,基本要素就是链表的一个小块,这个小块自己带着的数据以及指向前后位置的指针组成。初始…

关于VUE3的数据

接口请求出来的数据一般为对象类型的这里有三种方法存储数据&#xff1a;refreactive([])不太推荐reactive&#xff08;[]&#xff09;嵌套一个对象去存储&#xff0c;推荐1、ref<template><van-swipe :autoplay"3000"lazy-render><van-swipe-itemv-f…

2023-03-25 Android app 通过蓝牙(BLE低功耗蓝牙)实现设备间通讯的一个可用实例

一、两台android 手机之间的ble 蓝牙通信&#xff0c;不要蓝牙匹配&#xff0c;也是可以互传数据。 二、主要代码参考下面的文章&#xff1a; 1、主要参考 Android通过蓝牙&#xff08;BLE低功耗蓝牙&#xff09;实现设备间通讯 | 客户端 | 服务端_蓝牙beaon server_Code-Por…