Docs Menu
Docs Home
/
MongoDB Compass
/ /

스키마 내보내기

이 페이지의 내용

  • 스키마 객체 속성
  • 스키마 예제

스키마를 분석한 후 내보낼 수 있습니다. 이 기능은 스키마를 공유하고 컬렉션 간에 스키마를 비교할 때 유용합니다.

아직 스키마를 분석하지 않았다면 스키마를 분석하세요:

  1. 원하는 컬렉션을 선택하고 Schema 탭을 클릭합니다.

  2. Analyze Schema를 클릭합니다.

참고

Compass는 스키마를 분석할 때 컬렉션에서 임의의 문서 하위 집합을 샘플링합니다. 샘플링에 대해 자세히 알아보려면 샘플링을 참조하세요.

스키마 분석이 완료되면 스키마 내보내기:

  1. 상단 메뉴 표시줄에서 Collection을 클릭합니다.

  2. 드롭다운에서 Share Schema as JSON을 클릭합니다.

컬렉션 드롭다운을 보여주는 이미지

스키마가 JSON 객체로서 클립보드로 복사됩니다.

스키마 객체에는 countfields 속성이 있습니다:

  • count 스키마를 생성하기 위해 컬렉션에서 샘플링한 문서 수를 나타내는 정수입니다.

  • fields 샘플링 중에 분석된 문서의 각 필드에 해당하는 메타데이터 객체의 배열입니다. fields 배열의 각 요소에는 다음 필드가 포함되어 있습니다:

속성
데이터 유형
설명
name
문자열
해당 필드의 이름(예: _id.
path
문자열
문서 내 해당 필드의 경로.
count
Integer
해당 필드가 표시되는 문서 수입니다.
types
배열
해당 필드에 나타나는 각 데이터 유형을 나타내는 메타데이터 객체의 배열입니다.
types[n].name
문자열
이 데이터 유형의 이름입니다.
types[n].bsonType
문자열
이 데이터 유형의 BSON 유형.
types[n].path
문자열
문서 내 해당 필드의 경로.
types[n].count
Integer
이 데이터 유형이 해당 필드에 나타나는 횟수.
types[n].values
배열
해당 필드에 표시되고 이 데이터 유형과 일치하는 실제 샘플링된 값의 배열.
types[n].total_count
Integer
해당 필드가 배열인 경우 해당 배열의 요소 수.
types[n].probability
번호
임의의 문서에서 해당 필드의 값이 이 데이터 유형일 확률입니다.
types[n].unique
Integer
해당 필드에 표시되는 이 데이터 유형의 고유한 값의 수입니다.
types[n].has_duplicates
부울
true 이 데이터 유형의 단일 값이 해당 필드에 여러 번 나타나는 경우 그렇지 않으면 false.
types[n].lengths
배열
이 데이터 유형이 배열인 경우 해당 필드에서 발견된 배열의 길이를 나타내는 정수 배열입니다. 다른 데이터 유형에는 존재하지 않습니다.
types[n].average_length
번호
이 데이터 유형이 배열인 경우 샘플링된 문서 전체에서 해당 필드에 있는 배열의 평균 길이입니다. 다른 데이터 유형에는 존재하지 않습니다.
total_count
Integer
컬렉션에서 샘플링된 문서 수입니다.
type
문자열 또는 배열
해당 필드에 사용 가능한 유형을 나타내는 문자열 또는 문자열 배열입니다.
has_duplicates
부울
true 해당 필드에 단일 값이 여러 번 나타나는 경우. 그렇지 않으면 false.
probability
번호
임의의 문서에 해당 필드가 포함될 확률입니다.

다음 예에서는 각각 sport 필드와 해당 스포츠에 대한 고유 정보가 있는 세 개 문서가 포함된 컬렉션을 사용합니다.

1[
2 {
3 "_id": { "$oid":"5e8359ba7782b98ba98c16fd" },
4 "sport": "Baseball",
5 "equipment": [ "bat", "baseball", "glove", "helmet" ]
6 },
7 {
8 "_id": { "$oid":"5e835a727782b98ba98c16fe" },
9 "sport": "Football",
10 "variants": {
11 "us":"Soccer",
12 "eu":"Football"
13 }
14 },
15 {
16 "_id": { "$oid":"5e835ade7782b98ba98c16ff" },
17 "sport": "Cricket",
18 "origin": "England"
19 }
20]

위 예제를 MongoDB Compass로 가져와서 스키마 출력을 실험할 수 있습니다. 예제 컬렉션을 MongoDB Compass로 가져오려면 다음을 수행하세요.

  1. Copy 위의 JSON 문서를 참조하세요.

  2. MongoDB Compass에서 컬렉션을 선택하거나 새 컬렉션을 생성하여 복사한 문서를 가져옵니다. Documents 탭이 표시됩니다.

  3. Add Data를 클릭합니다.

  4. 드롭다운 메뉴에서 Insert Document 을(를) 선택합니다.

  5. 대화 상자의 JSON 보기에서 복사한 문서를 붙여넣고 Insert를 클릭합니다.

위의 예는 다음 스키마를 출력합니다:

1{
2 "fields": [
3 {
4 "name": "_id",
5 "path": "_id",
6 "count": 3,
7 "types": [
8 {
9 "name": "ObjectID",
10 "bsonType": "ObjectID",
11 "path": "_id",
12 "count": 3,
13 "values": [
14 "5e8359ba7782b98ba98c16fd",
15 "5e835a727782b98ba98c16fe",
16 "5e835ade7782b98ba98c16ff"
17 ],
18 "total_count": 0,
19 "probability": 1,
20 "unique": 3,
21 "has_duplicates": false
22 }
23 ],
24 "total_count": 3,
25 "type": "ObjectID",
26 "has_duplicates": false,
27 "probability": 1
28 },
29 {
30 "name": "equipment",
31 "path": "equipment",
32 "count": 1,
33 "types": [
34 {
35 "name": "Undefined",
36 "type": "Undefined",
37 "path": "equipment",
38 "count": 2,
39 "total_count": 0,
40 "probability": 0.6666666666666666,
41 "unique": 1,
42 "has_duplicates": true
43 },
44 {
45 "name": "Array",
46 "bsonType": "Array",
47 "path": "equipment",
48 "count": 1,
49 "types": [
50 {
51 "name": "String",
52 "bsonType": "String",
53 "path": "equipment",
54 "count": 4,
55 "values": [
56 "bat",
57 "baseball",
58 "glove",
59 "helmet"
60 ],
61 "total_count": 0,
62 "probability": 1,
63 "unique": 4,
64 "has_duplicates": false
65 }
66 ],
67 "lengths": [
68 4
69 ],
70 "total_count": 4,
71 "probability": 0.3333333333333333,
72 "average_length": 4
73 }
74 ],
75 "total_count": 3,
76 "type": [
77 "Undefined",
78 "Array"
79 ],
80 "has_duplicates": true,
81 "probability": 0.3333333333333333
82 },
83 {
84 "name": "origin",
85 "path": "origin",
86 "count": 1,
87 "types": [
88 {
89 "name": "Undefined",
90 "type": "Undefined",
91 "path": "origin",
92 "count": 2,
93 "total_count": 0,
94 "probability": 0.6666666666666666,
95 "unique": 1,
96 "has_duplicates": true
97 },
98 {
99 "name": "String",
100 "bsonType": "String",
101 "path": "origin",
102 "count": 1,
103 "values": [
104 "England"
105 ],
106 "total_count": 0,
107 "probability": 0.3333333333333333,
108 "unique": 1,
109 "has_duplicates": false
110 }
111 ],
112 "total_count": 3,
113 "type": [
114 "Undefined",
115 "String"
116 ],
117 "has_duplicates": true,
118 "probability": 0.3333333333333333
119 },
120 {
121 "name": "sport",
122 "path": "sport",
123 "count": 3,
124 "types": [
125 {
126 "name": "String",
127 "bsonType": "String",
128 "path": "sport",
129 "count": 3,
130 "values": [
131 "Baseball",
132 "Football",
133 "Cricket"
134 ],
135 "total_count": 0,
136 "probability": 1,
137 "unique": 3,
138 "has_duplicates": false
139 }
140 ],
141 "total_count": 3,
142 "type": "String",
143 "has_duplicates": false,
144 "probability": 1
145 },
146 {
147 "name": "variants",
148 "path": "variants",
149 "count": 1,
150 "types": [
151 {
152 "name": "Undefined",
153 "type": "Undefined",
154 "path": "variants",
155 "count": 2,
156 "total_count": 0,
157 "probability": 0.6666666666666666,
158 "unique": 1,
159 "has_duplicates": true
160 },
161 {
162 "name": "Document",
163 "bsonType": "Document",
164 "path": "variants",
165 "count": 1,
166 "fields": [
167 {
168 "name": "eu",
169 "path": "variants.eu",
170 "count": 1,
171 "types": [
172 {
173 "name": "String",
174 "bsonType": "String",
175 "path": "variants.eu",
176 "count": 1,
177 "values": [
178 "Football"
179 ],
180 "total_count": 0,
181 "probability": 1,
182 "unique": 1,
183 "has_duplicates": false
184 }
185 ],
186 "total_count": 1,
187 "type": "String",
188 "has_duplicates": false,
189 "probability": 1
190 },
191 {
192 "name": "us",
193 "path": "variants.us",
194 "count": 1,
195 "types": [
196 {
197 "name": "String",
198 "bsonType": "String",
199 "path": "variants.us",
200 "count": 1,
201 "values": [
202 "Soccer"
203 ],
204 "total_count": 0,
205 "probability": 1,
206 "unique": 1,
207 "has_duplicates": false
208 }
209 ],
210 "total_count": 1,
211 "type": "String",
212 "has_duplicates": false,
213 "probability": 1
214 }
215 ],
216 "total_count": 0,
217 "probability": 0.3333333333333333
218 }
219 ],
220 "total_count": 3,
221 "type": [
222 "Undefined",
223 "Document"
224 ],
225 "has_duplicates": true,
226 "probability": 0.3333333333333333
227 }
228 ],
229 "count": 3
230}

돌아가기

데이터 스키마 분석