Docs Menu
Docs Home
/
Compass
/ /

スキーマのエクスポート

スキーマを分析した後、エクスポートすることができます。これは、スキーマを共有したり、コレクション間でスキーマを比較したりする場合に役立ちます。

まだ行っていない場合は、スキーマを分析します。

1

目的のコレクションを選択し、Schema タブをクリックします。

2

[Analyze Schema] をクリックします。

Compass がスキーマを分析すると、コレクションからドキュメントのランダムなサブセットをサンプリングします。サンプリングについて詳しくは、「サンプリング」を参照してください。

スキーマが分析されたら、次の手順でスキーマをエクスポートします。

1
スキーマのエクスポートボタンを示す画像

[Export Schema] ボタンはビューポートの左上隅に表示されます。

2

Export JSON Schema モーダルで、エクスポートする形式を選択します。

Export JSON Schema modal
クリックして拡大します

スキーマは次の形式にエクスポートできます。

  • 標準形式

  • MongoDB形式

  • 拡張形式

3

スキーマを保存するファイルシステム上の場所を選択します。

標準形式のスキーマオブジェクトには、次のフィールドが含まれています。

プロパティ
データ型
説明

type

文字列または配列

required

文字列の配列

スキーマに表示する必要があるフィールド。詳細については、公式 JSON ドキュメントの「required」セクションを参照してください。

properties

オブジェクト

各フィールドのプロパティ 。キーはプロパティ名で、値はサブスキーマです。詳細については、 プロパティの公式JSONドキュメントを参照してください 。

items

ドキュメント

配列フィールド内の要素に関するメタデータ。メタデータは埋め込みサブスキーマとして表示されます。詳細については、公式 JSON ドキュメントの「items」セクションを参照してください。

これは、使用可能なすべてのフィールドを網羅するものではありません。追加フィールドの詳細については、公式のJSON schema 仕様 を参照してください。

MongoDB形式のスキーマオブジェクトには次のフィールドが含まれています。

プロパティ
データ型
説明

bsonType

文字列または複数の文字列の配列

このフィールドの BSON 型。

required

文字列の配列

スキーマに表示する必要があるフィールド。

properties

ドキュメント

各フィールドのプロパティ 。キーはプロパティ名で、値はサブスキーマです。

items

ドキュメント

配列フィールド内の要素に関するメタデータ。メタデータは埋め込みサブスキーマとして表示されます。

これは、使用可能なすべてのフィールドを網羅するものではありません。追加フィールドの詳細については、公式のJSON schema 仕様 を参照してください。

拡張形式スキーマ オブジェクトには、標準スキーマ フィールドに加えて、これらのフィールドが含まれています。

プロパティ
データ型
説明

x-bsonType

文字列または配列

このフィールドの BSON 型。

x-metadata

ドキュメント

フィールドに関するメタデータを含むドキュメント。

hasDuplicates

ブール値

true このフィールドに単一の値が複数回出現する場合は、。それ以外の場合は false

probability

float

フィールドがランダムなドキュメントに存在する確率。

count

integer

このフィールドを持つサンプルからのドキュメントの数。

x-sampleValues

配列

拡張JSONとしてのサンプル値。サンプル値は最初の 100 文字に制限されています。

これは、使用可能なすべてのフィールドを網羅するものではありません。追加フィールドの詳細については、公式のJSON schema 仕様 を参照してください。

Compass は、1000 を超える異なるフィールドを持つスキーマをエクスポートできません。1000 個を超えるフィールドを含むスキーマをエクスポートしようとすると、Compass はエラーを返します。

次の例では、それぞれが titleフィールドとその映画に関する固有の情報を持つ 3 ドキュメントのコレクションを使用します。

1[
2 {
3 "_id": { "$oid": "573a1390f29313caabcd6223" },
4 "title": "The Poor Little Rich Girl",
5 "plot": "Gwen's family is rich, but her parents ignore her and most of the serv...",
6 "year": 1917,
7 },
8 {
9 "_id": { "$oid": "573a1391f29313caabcd7616" },
10 "title": "Salomè",
11 "plot": "Salome, the daughter of Herodias, seduces her step-father/uncle Herod, ...",
12 "year": 1922,
13 "genres": [ "drama", "horror" ]
14 },
15 {
16 "_id": { "$oid": "573a1392f29313caabcd9c1b" },
17 "title": "Payment Deferred",
18 "year": 1932,
19 },
20]

上記の例を MongoDB Compass にインポートして、スキーマ出力を試すことができます。サンプル コレクションを MongoDB Compass にインポートするには、次の手順を行います。

1

上の JSON ドキュメントをコピーします。

2

MongoDB Compass で、コピーしたドキュメントをインポートするコレクションを選択するか、新しいコレクションを作成します。Documents タブが表示されます。

3
4
5

ダイアログの JSON ビューで、コピーしたドキュメントを貼り付けて Insert をクリックします。

上記の例では、次のスキーマが出力されます。

1{
2 "$schema": "https://json-schema.org/draft/2020-12/schema",
3 "type": "object",
4 "required": [
5 "_id",
6 "title",
7 "year"
8 ],
9 "properties": {
10 "_id": {
11 "$ref": "#/$defs/ObjectId"
12 },
13 "genres": {
14 "type": "array",
15 "items": {
16 "type": "string"
17 }
18 },
19 "plot": {
20 "type": "string"
21 },
22 "title": {
23 "type": "string"
24 },
25 "year": {
26 "type": "integer"
27 }
28 },
29 "$defs": {
30 "ObjectId": {
31 "type": "object",
32 "properties": {
33 "$oid": {
34 "type": "string",
35 "pattern": "^[0-9a-fA-F]{24}$"
36 }
37 },
38 "required": [
39 "$oid"
40 ],
41 "additionalProperties": false
42 }
43 }
44}
1{
2 "$jsonSchema": {
3 "bsonType": "object",
4 "required": [
5 "_id",
6 "title",
7 "year"
8 ],
9 "properties": {
10 "_id": {
11 "bsonType": "objectId"
12 },
13 "genres": {
14 "bsonType": "array",
15 "items": {
16 "bsonType": "string"
17 }
18 },
19 "plot": {
20 "bsonType": "string"
21 },
22 "title": {
23 "bsonType": "string"
24 },
25 "year": {
26 "bsonType": "int"
27 }
28 }
29 }
30}

サンプル値は最初の 100 文字に制限されています。

1{
2 "type": "object",
3 "x-bsonType": "object",
4 "required": [
5 "_id",
6 "title",
7 "year"
8 ],
9 "properties": {
10 "_id": {
11 "$ref": "#/$defs/ObjectId",
12 "x-bsonType": "objectId",
13 "x-metadata": {
14 "hasDuplicates": false,
15 "probability": 1,
16 "count": 3
17 },
18 "x-sampleValues": [
19 "573a1391f29313caabcd7616",
20 "573a1392f29313caabcd9c1b",
21 "573a1390f29313caabcd6223"
22 ]
23 },
24 "genres": {
25 "type": "array",
26 "x-bsonType": "array",
27 "x-metadata": {
28 "hasDuplicates": true,
29 "probability": 0.3333333333333333,
30 "count": 1
31 },
32 "items": {
33 "type": "string",
34 "x-bsonType": "string",
35 "x-metadata": {
36 "hasDuplicates": false,
37 "probability": 1,
38 "count": 2
39 },
40 "x-sampleValues": [
41 "drama",
42 "horror"
43 ]
44 }
45 },
46 "plot": {
47 "type": "string",
48 "x-bsonType": "string",
49 "x-metadata": {
50 "hasDuplicates": false,
51 "probability": 0.6666666666666666,
52 "count": 2
53 },
54 "x-sampleValues": [
55 "Salome, the daughter of Herodias, seduces her step-father/uncle Herod, ...",
56 "Gwen's family is rich, but her parents ignore her and most of the serv..."
57 ]
58 },
59 "title": {
60 "type": "string",
61 "x-bsonType": "string",
62 "x-metadata": {
63 "hasDuplicates": false,
64 "probability": 1,
65 "count": 3
66 },
67 "x-sampleValues": [
68 "Salomè",
69 "Payment Deferred",
70 "The Poor Little Rich Girl"
71 ]
72 },
73 "year": {
74 "type": "integer",
75 "x-bsonType": "int",
76 "x-metadata": {
77 "hasDuplicates": false,
78 "probability": 1,
79 "count": 3
80 },
81 "x-sampleValues": [
82 1922,
83 1932,
84 1917
85 ]
86 }
87 },
88 "$defs": {
89 "ObjectId": {
90 "type": "object",
91 "properties": {
92 "$oid": {
93 "type": "string",
94 "pattern": "^[0-9a-fA-F]{24}$"
95 }
96 },
97 "required": [
98 "$oid"
99 ],
100 "additionalProperties": false
101 }
102 }
103}

戻る

データスキーマの分析

項目一覧