0
0
MongoDBquery~5 mins

Memory and storage engine basics (WiredTiger) in MongoDB

Choose your learning style9 modes available
Introduction

Memory and storage engines help MongoDB save and manage your data efficiently. WiredTiger is the default engine that balances speed and storage.

When you want fast access to your data with good compression to save disk space.
When running MongoDB on a server with limited memory but need good performance.
When you want to handle many users reading and writing data at the same time.
When you want to use features like document-level locking for better concurrency.
Syntax
MongoDB
storage:
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: <number>
    collectionConfig:
      blockCompressor: <compressor_type>

This is part of the MongoDB configuration file (mongod.conf).

You can set cache size and compression type to control memory and storage behavior.

Examples
Basic setup to use WiredTiger as the storage engine.
MongoDB
storage:
  engine: wiredTiger
Set WiredTiger cache size to 2 GB to control memory usage.
MongoDB
storage:
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 2
Use Snappy compression to reduce disk space used by collections.
MongoDB
storage:
  engine: wiredTiger
  wiredTiger:
    collectionConfig:
      blockCompressor: snappy
Sample Program

This configuration tells MongoDB to use WiredTiger with 1 GB cache and zlib compression for collections.

MongoDB
# This is a mongod.conf snippet to configure WiredTiger
storage:
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1
    collectionConfig:
      blockCompressor: zlib
OutputSuccess
Important Notes

WiredTiger uses RAM as a cache to speed up data access.

Compression helps save disk space but may use more CPU.

You can tune cache size based on your server's memory to balance speed and resource use.

Summary

WiredTiger is MongoDB's default storage engine that balances speed and storage.

You configure it in mongod.conf by setting engine, cache size, and compression.

Proper tuning helps MongoDB run efficiently on your hardware.