当用户需要将集合 business.orders
中以 create_date
字段按年将数据切分到不同的子集合中。相应的切分配置如下表:
以下根据配置,实际生成集合 business.orders
创建集合 business.orders
,指定为主集合,分区键为 create_date
字段,分区方式为 range:
> db.business.createCL( "orders", { IsMainCL: true, ShardingKey: { create_date: 1 }, ShardingType: "range" } )
通过挂载操作,将主集合 business.orders
和两个子集合进行关联:
> db.business.orders.attachCL( "business.orders_2018", { LowBound: { create_date: "201801" }, UpBound: { create_date: "201901" } } )
> db.business.orders.attachCL( "business.orders_2019", { LowBound: { create_date: "201901" }, UpBound: { create_date: "202001" } } )
NOTE:
business.orders_2018
和business.orders_2019
可以是普通集合,也可以是数据库分区的集合。
用户可以通过快照命令查看分区的划分情况:
db.snapshot( SDB_SNAP_CATALOG, { Name: "business.orders" } )
{
...
"Name": "business.orders",
"IsMainCL": true,
"ShardingType": "range",
"ShardingKey": {
"create_date": 1
}
"CataInfo": [
{
"ID": 1,
"SubCLName": "business.orders_2018",
"LowBound": {
"create_date": "201801"
},
"UpBound": {
"create_date": "201901"
}
},
{
"ID": 2,
"SubCLName": "business.orders_2019",
"LowBound": {
"create_date": "201901"
},
"UpBound": {
"create_date": "202001"
}
}
]
}
相关阅读