Export Your Schema导出架构
On this page本页内容
You can export your schema after analyzing it. 您可以在分析架构后导出它。This is useful for sharing your schema and comparing schemas across collections.这对于共享架构和跨集合比较架构非常有用。
If you have not already done so, analyze your schema:如果您还没有这样做,请分析您的模式:
Select your desired collection and click the Schema tab.选择所需的集合,然后单击“架构”选项卡。Click Analyze Schema.单击“分析架构”。
Once your schema has been analyzed, export your schema:分析完架构后,导出架构:
In the top menu bar, click Collection.在顶部菜单栏中,单击“集合”。From the dropdown, click Share Schema as JSON.从下拉列表中,单击“将架构共享为JSON”。

Your schema is copied to your clipboard as a JSON object.架构将作为JSON对象复制到剪贴板。
Schema Object Properties架构对象属性
Schema objects have 架构对象具有count
and fields
properties:count
和fields
属性:
count
is an integer that represents the number of documents sampled from the collection to generate the schema.是一个整数,表示从集合中采样以生成架构的文档数。fields
is an array of metadata objects that correspond to each field in the documents analyzed during sampling.是与采样期间分析的文档中的每个字段相对应的元数据对象数组。Each element in thefields
array contains the following fields:fields
数组中的每个元素都包含以下字段:
name | String | _id ._id 。 |
path | String | |
count | Integer | |
types | Array | |
types[n].name | String | |
types[n].bsonType | String | |
types[n].path | String | |
types[n].count | Integer | |
types[n].values | Array | |
types[n].total_count | Integer | |
types[n].probability | Number | |
types[n].unique | Integer | |
types[n].has_duplicates | Boolean | true if a single value of this data type appears multiple times in the corresponding field. true 。false .false 。 |
types[n].lengths | Array | |
types[n].average_length | Number | |
total_count | Integer | |
type | String or Array | |
has_duplicates | Boolean | true if a single value appears multiple times in the corresponding field. true 。false .false 。 |
probability | Number |
Example Schema架构示例
The following example uses a collection of 3 documents, each with a 以下示例使用了3个文档的集合,每个文档都有一个sport
field and unique information about that sport:sport
字段和有关该运动的唯一信息:
[
{
"_id": { "$oid":"5e8359ba7782b98ba98c16fd" },
"sport": "Baseball",
"equipment": [ "bat", "baseball", "glove", "helmet" ]
},
{
"_id": { "$oid":"5e835a727782b98ba98c16fe" },
"sport": "Football",
"variants": {
"us":"Soccer",
"eu":"Football"
}
},
{
"_id": { "$oid":"5e835ade7782b98ba98c16ff" },
"sport": "Cricket",
"origin": "England"
}
]
You can import the above example to MongoDB Compass to experiment with schema outputs. 您可以将上面的示例导入MongoDB Compass,以尝试模式输出。To import the example collection into MongoDB Compass:要将示例集合导入MongoDB Compass,请执行以下操作:
Copy the JSON documents above.复制上面的JSON文档。In MongoDB Compass, select a collection or create a new collection to import the copied documents to.在MongoDB Compass中,选择一个集合或创建一个新集合来导入复制的文档。The Documents tab displays.此时将显示“文档”选项卡。Click Add Data.单击“添加数据”。Select Insert Document from the dropdown.从下拉列表中选择“插入文档”。In the JSON view of the dialog, paste the copied documents and click Insert.在对话框的JSON视图中,粘贴复制的文档,然后单击“插入”。
The example above outputs the following schema:上面的示例输出以下模式:
{
"fields": [
{
"name": "_id",
"path": "_id",
"count": 3,
"types": [
{
"name": "ObjectID",
"bsonType": "ObjectID",
"path": "_id",
"count": 3,
"values": [
"5e8359ba7782b98ba98c16fd",
"5e835a727782b98ba98c16fe",
"5e835ade7782b98ba98c16ff"
],
"total_count": 0,
"probability": 1,
"unique": 3,
"has_duplicates": false
}
],
"total_count": 3,
"type": "ObjectID",
"has_duplicates": false,
"probability": 1
},
{
"name": "equipment",
"path": "equipment",
"count": 1,
"types": [
{
"name": "Undefined",
"type": "Undefined",
"path": "equipment",
"count": 2,
"total_count": 0,
"probability": 0.6666666666666666,
"unique": 1,
"has_duplicates": true
},
{
"name": "Array",
"bsonType": "Array",
"path": "equipment",
"count": 1,
"types": [
{
"name": "String",
"bsonType": "String",
"path": "equipment",
"count": 4,
"values": [
"bat",
"baseball",
"glove",
"helmet"
],
"total_count": 0,
"probability": 1,
"unique": 4,
"has_duplicates": false
}
],
"lengths": [
4
],
"total_count": 4,
"probability": 0.3333333333333333,
"average_length": 4
}
],
"total_count": 3,
"type": [
"Undefined",
"Array"
],
"has_duplicates": true,
"probability": 0.3333333333333333
},
{
"name": "origin",
"path": "origin",
"count": 1,
"types": [
{
"name": "Undefined",
"type": "Undefined",
"path": "origin",
"count": 2,
"total_count": 0,
"probability": 0.6666666666666666,
"unique": 1,
"has_duplicates": true
},
{
"name": "String",
"bsonType": "String",
"path": "origin",
"count": 1,
"values": [
"England"
],
"total_count": 0,
"probability": 0.3333333333333333,
"unique": 1,
"has_duplicates": false
}
],
"total_count": 3,
"type": [
"Undefined",
"String"
],
"has_duplicates": true,
"probability": 0.3333333333333333
},
{
"name": "sport",
"path": "sport",
"count": 3,
"types": [
{
"name": "String",
"bsonType": "String",
"path": "sport",
"count": 3,
"values": [
"Baseball",
"Football",
"Cricket"
],
"total_count": 0,
"probability": 1,
"unique": 3,
"has_duplicates": false
}
],
"total_count": 3,
"type": "String",
"has_duplicates": false,
"probability": 1
},
{
"name": "variants",
"path": "variants",
"count": 1,
"types": [
{
"name": "Undefined",
"type": "Undefined",
"path": "variants",
"count": 2,
"total_count": 0,
"probability": 0.6666666666666666,
"unique": 1,
"has_duplicates": true
},
{
"name": "Document",
"bsonType": "Document",
"path": "variants",
"count": 1,
"fields": [
{
"name": "eu",
"path": "variants.eu",
"count": 1,
"types": [
{
"name": "String",
"bsonType": "String",
"path": "variants.eu",
"count": 1,
"values": [
"Football"
],
"total_count": 0,
"probability": 1,
"unique": 1,
"has_duplicates": false
}
],
"total_count": 1,
"type": "String",
"has_duplicates": false,
"probability": 1
},
{
"name": "us",
"path": "variants.us",
"count": 1,
"types": [
{
"name": "String",
"bsonType": "String",
"path": "variants.us",
"count": 1,
"values": [
"Soccer"
],
"total_count": 0,
"probability": 1,
"unique": 1,
"has_duplicates": false
}
],
"total_count": 1,
"type": "String",
"has_duplicates": false,
"probability": 1
}
],
"total_count": 0,
"probability": 0.3333333333333333
}
],
"total_count": 3,
"type": [
"Undefined",
"Document"
],
"has_duplicates": true,
"probability": 0.3333333333333333
}
],
"count": 3
}