mongodb_개요

구조

2900_resource/스크린샷 2024-04-13 오전 10.19.11.png
2900_resource/스크린샷 2024-04-13 오전 10.19.55.png
스크린샷 2024-04-13 오전 10.20.24 1.png


flowchart TD
    client("client app") --> driver("driver (python, go..)")
    driver --> system_security("보안(인증/ 암호화)")
    driver --> system_management("관리(sharding/ replication)")
    driver --> system_query("쿼리 시스템(parser/ optimizer/ execution engine)")
    system_security --> storage_engine("스토리지 엔진 API")
    system_management --> storage_engine
    system_query --> storage_engine
    storage_engine --> wired_tiger("wired tiger C API")
    wired_tiger --> wired_tiger_schema("schema")
    wired_tiger --> wired_tiger_cursor("cursor")
    wired_tiger --> wired_tiger_transactions("transactions")
	
    wired_tiger_schema --> E11["Metadata"]
    E11 --> wired_tiger_cursor
    wired_tiger_schema --> E12["dhandle / Btree"]
    wired_tiger_schema --> E12
    E12 --> E13["Row/Column Storage"]

    wired_tiger_transactions --> F2["Snapshots"]
    F2 --> F3["Eviction"]

    F3 --> G1["Block Manager"]
    E13 --> G1
    E13 --> G2["Cache"]
    G2 --> G1
    G2 --> H1["History Store"]
    H1 --> G1
    H1 --> wired_tiger_cursor
    

    wired_tiger_transactions --> H2["Logging"]
    H2 --> G1

    G1 --> I1["File System & OS interface"]
    I1 --> J1["Database Files"]
    I1 --> J2["Log Files"]

참고

schema

스크린샷 2024-04-13 오전 10.22.08.png

replica set

스크린샷 2024-04-13 오전 10.23.03.png

sharding

스크린샷 2024-04-13 오전 10.26.43.png

mongodb 기술

스크린샷 2024-04-13 오전 10.20.49.png

인메모리

mongodb 구조

mongodb 설계

기본 query/ Aggregate

etc query

monitoring

index

search vector

mongodb transaction :: spring

setup mongodb enterprise

mongo dump

mongodump —uri=“mongodb://mongodb0.example.com:27017” [additional options]

mongodump —uri=“mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myReplicaSetName” [additional option]

mongodump —host {111.111.111.0} —port 27017 —db {dataBase} —out {fileName}

mongodump —uri=“mongodb://10.166.238.112:30012” -u root -p test123 —authenticationDatabase=admin —db=test —collection=test —out=~/backup/mongodump-2023-10-10

mongorestore —host 127.0.0.1 —port 27017 —drop [삭제하려는DB이름] —db [복구하려는DB이름] [복구하려는 dumpFile 위치]

mongodb ops manager



fattern


라이프사이클



management

db.TB_LAYER2_ADVISOR.aggregate([
	{$indexStats: {}}
])

select

{
	collection: {
		locale: “en”,
		strength: 2 // 강도가 1, 2에서는 대소문자를 구분 안함
	}
}

insert

db.createCollection(”TB_LAYER2_ADVISOR”,
	{
		validator: {
			$jsonSchema: {
				bsonType: “object”,
				required: [“key1”, “key2”, “key3”, “key5”],
				properties: {
					key1: {
						bsonType: “string”,
						descripttion: “문자열 타입의 필수 항목“
					},
					key2: {
						bsonType: “int”,
						minnum : 2000,
						maxnum: 2030,
						descripttion: “[2000, 2030] 사이 정수 타입의 필수 항목“
					},
					key3: {
						enum: [”aws”, “azure”, “dscloud”, “hpc”, null],
						descripttion: “배열 요소 중 하나이며 필수 항목“
					},
					key4: {
						bsonType: [ “int” ],
						descripttion: “해당 필드가 존재한다면 정수 타입“
					},
					key5: {
						bsonType: “object”,
						required: [ “region” ],
						properties: {
							resourceId: {
								bsonType: “string”,
								description: “해당 필드가 존재한다면 문자열“
							},
							region: {
								bsonType: “string”,
								description: “문자열 타입의 필수 항목”
							}
						},
					},
				}
			}
		}
	}
)

update

db.seq_example.update(
	{
		“Name”: “js”,
	},
	{
		“$inc”: {”val”: 1}
	}
)

db.COLLECTN_NAME.updateMany(
 {
  <조건절>
 },
 [{
   $set: {
    <업데이트 구문>
   }
 }]
)
db.runCommand( 
	{collmond: “TB_LAYER2_ADVISOR”,
		validator: {
			$jsonSchema: {
				bsonType: “object”,
				required: [”key1”, “key2”],
				properties: {
					key1: {
						bsonType: “string”,
						description: “문자열 타입의 필수 항목 입니다.“
					},
				}
			}
		}	
	}
)

벤치마크

  1. mongostat
    • 서버의 상태를 실시간으로 확인
    • 쿼리 상태
  2. mongotop
    • mongodb 서버가 소비하는 정보 추적
  3. profilling
    • 쿼리 효율
  4. explain plans
    • explain 실행계획 확인