MongoDB 使用
安装
-
Homebrew:
brew tap mongodb/brew brew update brew install mongodb-community启动 MongoDB 服务:
brew services start mongodb-community相关路径(Apple Silicon):
- 配置文件路径:
/opt/homebrew/etc/mongod.conf - 日志文件路径:
/opt/homebrew/var/log/mongodb - 数据目录:
/opt/homebrew/var/mongodb
- 配置文件路径:
-
Docker:
拉取镜像:
docker pull mongodb/mongodb-community-server:latest启动容器:
docker run --name mongodb -p 27017:27017 -d mongodb/mongodb-community-server:latest
安装 Compass:
MongoDB Compass Download (GUI) | MongoDB
Compass 是 MongoDB 提供的一款图形化用户界面(GUI)工具,用于可视化地管理和分析 MongoDB 数据库。
使用
导入一个 JSON 文件:
mongoimport --db yourDatabaseName --collection yourCollectionName --file document.json
启动 MongoDB Shell:
mongosh
选中 Database:
use yourDatabaseName
MongoDB 中 Database 和 Collection 的关系:
- 数据库:
library- 集合:
books- 文档:
{ "title": "1984", "author": "George Orwell" } - 文档:
{ "title": "Brave New World", "author": "Aldous Huxley" }
- 文档:
- 集合:
members- 文档:
{ "name": "John Doe", "membership_id": "12345" }
- 文档:
- 集合:

浙公网安备 33010602011771号