文档菜单
文档首页
/
关系型迁移器
/

模式映射

在本页面上

  • 映射规则
  • 示例
  • 使用案例:去规范化表结构
  • 映射规则结果
  • 映射规则实现

模式映射是指您决定如何在目标MongoDB数据库中表示源关系模式的流程。通过自定义映射规则,在关系迁移器中简化模式映射过程。

在模式映射设计过程中,关系迁移器会自动从您的关系数据库模式中导出源数据模型。目标数据模型可以通过自定义

  • 映射规则选项

  • 项目ID字段选项

Schema Mapping Concept

本节提供了一种场景和示例实现,用于描述模式映射过程。此示例将关系数据模型转换为MongoDB数据模型。

使用MongoEnterprises关系数据库,目标是将所有数据库表扁平化,以便在单个MongoDB集合中提供所有订单和客户数据。

以下图像显示了使用关系迁移器进行反规范化的关系数据模型。

Relational Data Model

使用关系迁移器时,目标是实现以下MongoDB数据模型。Order集合包含从Customer、Order、Product和Order Line表中所有子元素。该集合包含迁移表的嵌套对象。结果看起来像这样

{
"_id": {
"OrderID": 1
},
"CustomerID": 1,
"OrderStatusID": 1,
"TotalAmount": 550,
"Customer": {
"CustomerID": 1,
"Name": "Joelynn Fawthrop",
"Address1": "86 Dwight Pass",
"Address2": "Carregal",
"Address3": "3800-854"
},
"OrderLines": [
{
"OrderLineID": 1,
"OrderID": 1,
"ProductID": 1,
"Quantity": 1,
"Product": {
"ProductID": 1,
"Name": "MongoDB 5.0 Action Figure",
"Price": 50
}
},
{
"OrderLineID": 4,
"OrderID": 1,
"ProductID": 3,
"Quantity": 1,
"Product": {
"ProductID": 3,
"Name": "Gold Plated MongoDB Compass",
"Price": 500
}
}
],
"OrderStatus": {
"OrderStatusID": 1,
"Name": "Order Placed"
}
}

使用关系迁移器实现目标数据模型结果,请配置Order表以下映射规则选项

关系表
映射规则类型
根路径
Order
新文档
不适用
OrderLine
OrderLines
Customer
Customer
OrderStatus
OrderStatus
Product
OrderLInes.Product

返回

映射规则