Docs 菜单
Docs 主页
/
Relational Migrator
/

模式映射

在此页面上

  • 映射规则
  • 例子
  • 用例非规范化表结构
  • 映射规则结果
  • 映射规则实施

模式映射是指决定如何在目标MongoDB database中表示源关系模式的过程。 通过自定义映射规则,促进 Relational Migrator 中的模式映射过程。

在模式映射设计过程中,Relational Migrator 会自动从关系数据库的模式中派生源数据模型。 可以通过以下自定义来影响目标数据模型:

  • 映射规则选项

  • 项目 ID 字段选项

模式映射概念

本节提供模式映射过程的场景和示例实现。 此示例将关系数据模型转换为 MongoDB 数据模型。

使用MongoEnterprises关系数据库,目标是展平所有的数据库表,以便所有的订单和客户数据在一个单独的MongoDB collection中可用。

下图显示了要使用 Relational Migrator 非规范化的关系数据模型。

关系Realm 数据模型

使用 Relational Migrator 时,目标是实现以下 MongoDB 数据模型。 Order集合包含CustomerOrderProductOrder 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"
}
}

要使用 Relational Migrator 实现目标数据模型结果,请使用以下映射规则选项配置Order表:

关系表
映射规则类型
根路径
来自一个购物车应用的order文档,
新建文档
不适用
OrderLine
OrderLines
客户
Customer
OrderStatus
OrderStatus
产品
OrderLInes.Product

后退

映射规则

来年

从关系创建规则