Grug
Grug

Reputation: 3

MongoDB WiredTiger use clustered index on _id field?

I know MongoDB WiredTiger use clustered index to store data. Is WiredTiger use clustered index on _id field or another key generate by WiredTiger?

Upvotes: 0

Views: 444

Answers (2)

Ali Can
Ali Can

Reputation: 574

Yes they are clustered and stored in wiredtiger files. For each index defined on collection, wiredtiger creates and manages separate index file.

"Prior to MongoDB 3.2, only B-tree was available in the storage layer. To increase its scalability, MongoDB added LSM Tree in later versions after it acquired WiredTiger" [1]

An LSM tree can provide better performance when we have a workload of random inserts that would otherwise overflow our page cache and start paging in data from disk to keep our index up to date.

To override default wiredtiger storage type configuration:

mongod --wiredTigerIndexConfigString "type=lsm,block_compressor=zlib"

Upvotes: 0

Joe
Joe

Reputation: 28336

WiredTiger uses a binary tree-like structure to store documents. It is a basic key-value store, where the key is an internally generated identifier, and the value is the document.

All indexes, including the one on the _id field, map field values to the internal identifier.

Upvotes: 1

Related Questions