Hi~朋友,关注置顶防止错过消息
Clustered Collection在MongoDB中索引和Document存储在同一个WiredTiger文件中,存储和索引更加高效,MongoDB 5.3以后支持创建聚簇集合,创建方式如下:
db.createCollection(
"stocks",
{ clusteredIndex: { "key": { _id: 1}, "unique": true, "name": "stocks clustered key"} }
)
创建该类型的结合时需要指定clusteredIndex此参数,已经存在的表可以通过以下命令检测是否时聚簇集合:
db.getCollectionInfos({name: "collection name"});
Clustered Collection好处
Clustered Collection限制
Clustered Collection自定义Index Key和value
通常情况下, clustered index key values会使用Document的ObjectId,但是也可以自定key value,但是key需要满足以下条件: