<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=MongoDB_for_Administrators</id>
	<title>MongoDB for Administrators - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=MongoDB_for_Administrators"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=MongoDB_for_Administrators&amp;action=history"/>
	<updated>2026-06-02T21:25:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=MongoDB_for_Administrators&amp;diff=68452&amp;oldid=prev</id>
		<title>Kbaran: /* Storage engine */</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=MongoDB_for_Administrators&amp;diff=68452&amp;oldid=prev"/>
		<updated>2018-09-07T12:03:45Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Storage engine&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:MongoDB]]&lt;br /&gt;
&lt;br /&gt;
{{Copyright Notice}}&lt;br /&gt;
&lt;br /&gt;
{{:Basics of MongoDB}}&lt;br /&gt;
&lt;br /&gt;
== Single-server Configuration and Deployment ==&lt;br /&gt;
&lt;br /&gt;
=== Configuration File Options ===&lt;br /&gt;
* YAML-based configuration file format (since 2.6)&lt;br /&gt;
** http://docs.mongodb.org/manual/reference/configuration-options/&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mongod --config /etc/mongodb.conf&lt;br /&gt;
mongod -f /etc/mongodb.conf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;yaml&amp;quot;&amp;gt;&lt;br /&gt;
net:&lt;br /&gt;
  port: 27017&lt;br /&gt;
  bindIp: 127.0.0.1&lt;br /&gt;
operationProfiling:&lt;br /&gt;
  mode: slowOp&lt;br /&gt;
  slowOpThresholdMs: 10&lt;br /&gt;
storage:&lt;br /&gt;
  dbPath: c:\data\db&lt;br /&gt;
  wiredTiger:&lt;br /&gt;
    engineConfig:&lt;br /&gt;
      cacheSizeGB: 1&lt;br /&gt;
systemLog:&lt;br /&gt;
  destination: file&lt;br /&gt;
  path: c:\data\logs\mongodb.log&lt;br /&gt;
security:&lt;br /&gt;
  authorization: enabled&lt;br /&gt;
  keyFile: c:\data\config\keyfile.txt&lt;br /&gt;
replication:&lt;br /&gt;
  replSetName: training&lt;br /&gt;
  oplogSizeMB: 128&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Storage engine ===&lt;br /&gt;
* A storage engine is the part of a database that is responsible for managing how data is stored on disk.&lt;br /&gt;
** in other words, it&amp;#039;s an interface between database and hardware&lt;br /&gt;
* MMAPv1 Storage Engine&lt;br /&gt;
** historically first storage engine&lt;br /&gt;
** collection level locking&lt;br /&gt;
** in-place updates&lt;br /&gt;
** power of 2 sized document allocations&lt;br /&gt;
* WiredTiger Storage Engine&lt;br /&gt;
** new in version 3.0&lt;br /&gt;
** default since 3.2&lt;br /&gt;
** improved performance in most use cases&lt;br /&gt;
** document level locking&lt;br /&gt;
** compression (for data and indexes)&lt;br /&gt;
* In-Memory (experimental)&lt;br /&gt;
* RocksDB, HDFS, FusionIO (under development)&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MMAPv1 ====&lt;br /&gt;
* --storageEngine mmapv1&lt;br /&gt;
* locks:&lt;br /&gt;
** multiple readers, single writer lock&lt;br /&gt;
** shared resources: data, metadata (indexes, journal)&lt;br /&gt;
* lock levels:&lt;br /&gt;
** database level locking (2.2 - 2.6)&lt;br /&gt;
** collection level locking (3.0)&lt;br /&gt;
* journal - write-ahead transaction log&lt;br /&gt;
** all operations are written to journal&lt;br /&gt;
** and after that are applied to data files&lt;br /&gt;
* data on disk is raw BSON, directly mapped into virtual memory&lt;br /&gt;
* document allocations&lt;br /&gt;
** no padding&lt;br /&gt;
** padding factor (automatic, manual)&lt;br /&gt;
** power of 2 sized allocations (from 32B to 2MB)&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== WiredTiger ====&lt;br /&gt;
* --storageEngine wiredTiger&lt;br /&gt;
* data is stored in B-Trees (similar to B-Trees MMAPv1 uses for indexes)&lt;br /&gt;
** initially documents get written into un-used regions&lt;br /&gt;
** and then merged with the rest of the data in background later&lt;br /&gt;
* WT uses two caches:&lt;br /&gt;
** WT cache (half of RAM by default)&lt;br /&gt;
** operating system cache&lt;br /&gt;
* it uses a write-ahead transaction log in combination with checkpoints to ensure data persistence&lt;br /&gt;
* MongoDB will commit a checkpoint to disk&lt;br /&gt;
** 60 seconds after the end of previous checkpoint or&lt;br /&gt;
** when there is to much dirty data in WT cache (2 gigabytes of data)&lt;br /&gt;
* document level locking &lt;br /&gt;
** WT has no locks but good concurrency protocols&lt;br /&gt;
** writes should scale with the number of threads&lt;br /&gt;
* compression (can be set for each collection separately)&lt;br /&gt;
** snappy (fast, balance storage efficiency and processing requirements)&lt;br /&gt;
** zlib (higher compression rates at the cost of more CPU)&lt;br /&gt;
** off&lt;br /&gt;
* WiredTiger options&lt;br /&gt;
* how to test your own data?&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;JavaScript&amp;quot;&amp;gt;&lt;br /&gt;
db.createCollection( &amp;quot;email&amp;quot;, { storageEngine: { wiredTiger: { configString: &amp;#039;block_compressor=zlib&amp;#039; }}})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Authentication and Authorization ===&lt;br /&gt;
* MongoDB employs Role-Based Access Control&lt;br /&gt;
* MongoDB supports&lt;br /&gt;
** password-based authentication (SCRAM-SHA-1, MONGODB-CR)&lt;br /&gt;
** x.509 certificates&lt;br /&gt;
** LDAP proxy (enterprise edition)&lt;br /&gt;
** Kerberos (enterprise edition)&lt;br /&gt;
* authentication is disabled by default&lt;br /&gt;
** to turn it on use --auth switch, &lt;br /&gt;
** create at least one superuser account before&lt;br /&gt;
* user belongs to a database and must be authenticated in that database&lt;br /&gt;
* users created in admin or local database can perform operations on all databases&lt;br /&gt;
* commonly used roles: read, readWrite, dbAdmin, userAdmin, dbOwner&lt;br /&gt;
* http://docs.mongodb.org/manual/core/authorization/&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;JavaScript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; use admin&lt;br /&gt;
&amp;gt; db.createUser({user : &amp;quot;ubuntu&amp;quot;, pwd : &amp;quot;NobleProg&amp;quot;, roles : [&amp;quot;root&amp;quot;]})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mongo -u ubuntu -p --authenticationDatabase admin&lt;br /&gt;
$ mongo localhost/admin -u ubuntu -p&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;JavaScript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; use admin&lt;br /&gt;
&amp;gt; db.auth(&amp;quot;ubuntu&amp;quot;, &amp;quot;NobleProg&amp;quot;)&lt;br /&gt;
&amp;gt; use test&lt;br /&gt;
&amp;gt; db.createUser({user: &amp;quot;testuser&amp;quot;, pwd: &amp;quot;NobleProg&amp;quot;, roles: [&amp;quot;dbOwner&amp;quot;]})&lt;br /&gt;
&amp;gt; db.getSiblingDB(&amp;quot;admin&amp;quot;).system.users.find().pretty()&lt;br /&gt;
&amp;gt; db.getUser(&amp;quot;testuser&amp;quot;)&lt;br /&gt;
&amp;gt; db.getRole(&amp;quot;dbOwner&amp;quot;)&lt;br /&gt;
&amp;gt; db.getRole(&amp;quot;dbOwner&amp;quot;, {showPrivileges: true})&lt;br /&gt;
&lt;br /&gt;
&amp;gt; db.grantRolesToUser(&amp;quot;testuser&amp;quot;, [{role: &amp;quot;read&amp;quot;, db: &amp;quot;dept&amp;quot;}])&lt;br /&gt;
&amp;gt; db.grantRolesToUser(&amp;quot;testuser&amp;quot;, [{role: &amp;quot;readWrite&amp;quot;, db: &amp;quot;dept&amp;quot;}])&lt;br /&gt;
&amp;gt; db.revokeRolesFromUser(&amp;quot;testuser&amp;quot;, [{role: &amp;quot;read&amp;quot;, db: &amp;quot;dept&amp;quot;}])&lt;br /&gt;
&amp;gt; db.grantRolesToUser(&amp;quot;testuser&amp;quot;, [{role: &amp;quot;dbAdmin&amp;quot;, db: &amp;quot;dept&amp;quot;}])&lt;br /&gt;
&lt;br /&gt;
&amp;gt; db.dropUser(&amp;quot;testuser&amp;quot;)&lt;br /&gt;
&amp;gt; db.logout()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;JavaScript&amp;quot;&amp;gt;&lt;br /&gt;
//how to create a custom role&lt;br /&gt;
&amp;gt; use admin&lt;br /&gt;
&amp;gt; db.auth(&amp;quot;ubuntu&amp;quot;, &amp;quot;NobleProg&amp;quot;)&lt;br /&gt;
&amp;gt; db.createUser({user: &amp;quot;monitoringuser&amp;quot;, pwd: &amp;quot;NobleProg&amp;quot;, roles: []})&lt;br /&gt;
&amp;gt; db.createRole({role: &amp;quot;statsWatcher&amp;quot;, privileges: [{resource: {&amp;quot;anyResource&amp;quot;: true}, actions: [&amp;quot;serverStatus&amp;quot;]}], roles: []})&lt;br /&gt;
&amp;gt; db.getRole(&amp;quot;statsWatcher&amp;quot;, {showPrivileges: true})&lt;br /&gt;
&amp;gt; db.grantRolesToUser(&amp;quot;monitoringuser&amp;quot;, [{role: &amp;quot;statsWatcher&amp;quot;, db: &amp;quot;admin&amp;quot;}])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Monitoring MongoDB ===&lt;br /&gt;
* mongotop&lt;br /&gt;
* mongostat&lt;br /&gt;
* MongoDB&amp;#039;s Web Console on port +1000&lt;br /&gt;
** enable &amp;#039;&amp;#039;&amp;#039;rest&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;httpinterface&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* MongoDB Monitoring Service (MMS)&lt;br /&gt;
** plus Munin for monitoring hardware&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;JavaScript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; db.serverStatus()&lt;br /&gt;
&amp;gt; db.runCommand(&amp;quot;serverStatus&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;JavaScript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; rs.status()&lt;br /&gt;
&amp;gt; db.runCommand(&amp;quot;replSetGetStatus&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;JavaScript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; db.currentOp()&lt;br /&gt;
&amp;gt; db.stats()&lt;br /&gt;
&amp;gt; db.collection.stats()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Profiler ===&lt;br /&gt;
* can be turned on database level or for entire server&lt;br /&gt;
* profiling levels:&lt;br /&gt;
** 0 - no profiling&lt;br /&gt;
** 1 - only includes &amp;quot;slow&amp;quot; operations&lt;br /&gt;
** 2 - includes all operations&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;JavaScript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; db.getProfilingLevel()&lt;br /&gt;
&amp;gt; db.setProfilingLevel(1, 100)&lt;br /&gt;
&amp;gt; db.system.profile.find().sort({millis : -1}).pretty()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{:Indexes in MongoDB}}&lt;br /&gt;
&lt;br /&gt;
{{:Replication in MongoDB}}&lt;br /&gt;
&lt;br /&gt;
{{:Backup and Restore in MongoDB}}&lt;br /&gt;
&lt;br /&gt;
== Other Administrative Tasks ==&lt;br /&gt;
* Preheating data&lt;br /&gt;
** loading everything into memory&lt;br /&gt;
** loading selected collections only&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; db.runCommand({ touch: &amp;quot;collectionName&amp;quot;, data: true, index: true })&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
** loading specific indexes&lt;br /&gt;
** loading recently created documents&lt;br /&gt;
** replay application usage&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Compacting&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; db.runCommand({&amp;quot;compact&amp;quot; : &amp;quot;collectionName&amp;quot;, &amp;quot;paddingFactor&amp;quot; : 1.5})&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Repairing data&lt;br /&gt;
** use --repair and optionally --repairpath&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt; db.repairDatabase()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kbaran</name></author>
	</entry>
</feed>