gpt4 book ai didi

MongoDB:如何更改 _id_ 索引的引擎类型(从 B-Tree 到 LSM-Tree)?

转载 作者:行者123 更新时间:2023-12-02 03:02:21 24 4
gpt4 key购买 nike

我们可以使用WiredTiger引擎和type=lsm创建一个集合,但是MongoDB文档中没有提到这个功能:

db.createCollection(
"test",
{ storageEngine: { wiredTiger: {configString: "type=lsm"}}}
)

一旦插入一些文档并添加索引,WiredTiger 似乎确实创建了 LSM 文件。

db.test.insert([
{ value: 1},
{ value: 2},
{ value: 3}
]) // Done in 16:04
db.test.createIndex(
{ value: 1 },
{ storageEngine: { wiredTiger: {configString: "type=lsm"}}}
) // Done in 19:59
$ ls -ltr
...
-rw-r--r--. 1 mongod mongod 16384 Jan 15 16:04 collection-0-1708338433081558809-000002.lsm
-rw-r--r--. 1 mongod mongod 16384 Jan 15 16:04 index-1-1708338433081558809.wt
-rw-r--r--. 1 mongod mongod 16384 Jan 15 19:59 index-3-1708338433081558809-000002.lsm

集合和索引 value_1 看起来像 LSM-Tree,但索引 _id_ 仍然看起来像 B-Tree。

如何更改索引_id的引擎类型?

最佳答案

这不是您想听到的答案,但目前不可能。

_id是一个比较特殊的索引。来自https://github.com/mongodb/mongo/blob/73b456d5c059b17d1c7f0f8badb7c72391ee2173/src/mongo/db/catalog/index_key_validate.cpp#L74:

所有索引的规范验证器:

static std::set<StringData> allowedFieldNames = {
IndexDescriptor::k2dIndexBitsFieldName,
IndexDescriptor::k2dIndexMaxFieldName,
IndexDescriptor::k2dIndexMinFieldName,
IndexDescriptor::k2dsphereCoarsestIndexedLevel,
IndexDescriptor::k2dsphereFinestIndexedLevel,
IndexDescriptor::k2dsphereVersionFieldName,
IndexDescriptor::kBackgroundFieldName,
IndexDescriptor::kCollationFieldName,
IndexDescriptor::kDefaultLanguageFieldName,
IndexDescriptor::kDropDuplicatesFieldName,
IndexDescriptor::kExpireAfterSecondsFieldName,
IndexDescriptor::kGeoHaystackBucketSize,
IndexDescriptor::kIndexNameFieldName,
IndexDescriptor::kIndexVersionFieldName,
IndexDescriptor::kKeyPatternFieldName,
IndexDescriptor::kLanguageOverrideFieldName,
IndexDescriptor::kNamespaceFieldName,
IndexDescriptor::kPartialFilterExprFieldName,
IndexDescriptor::kPathProjectionFieldName,
IndexDescriptor::kSparseFieldName,
IndexDescriptor::kStorageEngineFieldName,
IndexDescriptor::kTextVersionFieldName,
IndexDescriptor::kUniqueFieldName,
IndexDescriptor::kWeightsFieldName,
// Index creation under legacy writeMode can result in an index spec with an _id field.
"_id"};

_id 索引允许的规范:

static const std::set<StringData> allowedIdIndexFieldNames = {
IndexDescriptor::kCollationFieldName,
IndexDescriptor::kIndexNameFieldName,
IndexDescriptor::kIndexVersionFieldName,
IndexDescriptor::kKeyPatternFieldName,
IndexDescriptor::kNamespaceFieldName,
// Index creation under legacy writeMode can result in an index spec with an _id field.
"_id"};

如您所见,除了名称、排序规则、版本等之外,您可以灵活地更改任何内容。那里没有 kStorageEngineFieldName

关于MongoDB:如何更改 _id_ 索引的引擎类型(从 B-Tree 到 LSM-Tree)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59751187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com