분류
1. 개요 [편집]
2. 설치 Guide [편집]
- MongoDB 는 공식사이트의 Install 문서가 정말 잘 정리되어 있기로 유명하다.
- 굳이 다른 블로그나 AI문의하기 보단 공식 문서를 참조해보고, 잘 안되는 부분은 검색을 활용해서 해결하자.
- Ubuntu 계열 설치 방법: 우분투 설치 공식 문서
- Red Hat 계열 설치 방법: Red Hat계열 설치 공식 문서
- Debian 계열 설치 방법: Debian 계열 설치 공식 문서
2.1. 설치 후 최초 설정 [편집]
- 아래 내용은 mongoDB 8버전대 기준으로 설명함.
- mongosh 명령어로 mongoDB CLI 환경 진입
- db.createUser를 통해 admin ID 생성
- 예시
db.createUser(
{
user: "kskim",
pwd: passwordPrompt(),
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" }
]
}
)
- 이후 admin ID를 통해 다른 사용자 ID나 추가 작업 수행
- 예시
#mongosh
Current Mongosh Log ID: 67f745b38d50f7b8b9d861df
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&>appName=mongosh+2.5.0
Using MongoDB: 8.0.6
Using Mongosh: 2.5.0
For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/
To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.The server generated these startup warnings when booting
2025-04-10T02:35:54.496+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2025-04-10T02:35:56.152+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2025-04-10T02:35:56.155+00:00: You are running on a NUMA machine. We suggest launching mongod like this to avoid performance problems: numactl --interleave=all mongod [other options]
2025-04-10T02:35:56.156+00:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile
2025-04-10T02:35:56.156+00:00: For customers running the current memory allocator, we suggest changing the contents of the following sysfsFile
2025-04-10T02:35:56.156+00:00: We suggest setting the contents of sysfsFile to 0.
2025-04-10T02:35:56.156+00:00: We suggest setting swappiness to 0 or 1, as swapping can cause performance problems.
test> use admin
switched to db admin
admin> db.createUser(
... {
... user: "kskim",
... pwd: passwordPrompt(),
... roles: [
... { role: "userAdminAnyDatabase", db: "admin" },
... { role: "readWriteAnyDatabase", db: "admin" }
... ]
... }
... )
Enter password
**********{ ok: 1 }
admin> exit
3. 백업 및 복구 [편집]
- 아래 내용은 mongoDB 8버전대 기준으로 설명함.
- 역시 공식 사이트에 백업 방법들과 예시가 소개가 되어있다.
- 공식 사이트 백업파트: 백업 공식 문서
- 여기에서는 실제 일부 명령어만 기록한다.
3.1. 백업 [편집]
3.2. 복원 [편집]
- 이후 해당 DB CLI 또는 UI Client로 접속해서 해당 DB값을 확인한다.
3.3. 복원 후 확인 방법 [편집]
- mongoDB shell(mongosh) CLI 진입 후
- DB전체의 용량 확인.
- 전체 용량이 비슷하다면 잘 복원되었을 가능성이 높다.
db.stats().dataSize
- Collection 개수 확인.
- 양쪽의 Collection의 개수를 확인한다.
show collections
- 각 collection 별로 내부 데이터 개수 확인.
db.(coleection 이름).estimatedDocumentCount()