Skip to content

Commit 15b48d2

Browse files
committed
DOCS-11802,DOCS-11758,DOCS-11505: txn inmemory storage engine, create/drop collection before txn, data model updates, atomicity/isolation updates
1 parent 1c889af commit 15b48d2

30 files changed

+380
-370
lines changed

source/core/data-model-design.txt

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,33 @@ as well as the ability to request and retrieve related data in a single
4848
database operation. Embedded data models make it possible to update
4949
related data in a single atomic write operation.
5050

51-
However, embedding related data in documents may lead to situations
52-
where documents grow after creation. With the MMAPv1 storage engine,
53-
document growth can impact write performance and lead to data
54-
fragmentation.
55-
56-
In version 3.0.0, MongoDB uses :ref:`power-of-2-allocation` as the
57-
default allocation strategy for MMAPv1 in order to account for document
58-
growth, minimizing the likelihood of data fragmentation. See
59-
:ref:`power-of-2-allocation` for details. Furthermore, documents in
60-
MongoDB must be smaller than the :limit:`maximum BSON document size
61-
<BSON Document Size>`. For bulk binary data, consider :doc:`GridFS
51+
To access data within embedded documents, use :term:`dot notation` to
52+
"reach into" the embedded documents. See :ref:`query for data in arrays
53+
<read-operations-arrays>` and :ref:`query data in embedded documents
54+
<read-operations-embedded-documents>` for more examples on accessing
55+
data in arrays and embedded documents.
56+
57+
Embedded Data Model and Document Size Limit
58+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59+
60+
Documents in MongoDB must be smaller than the :limit:`maximum BSON
61+
document size <BSON Document Size>`.
62+
63+
For bulk binary data, consider :doc:`GridFS
6264
</core/gridfs>`.
6365

64-
To interact with embedded documents, use :term:`dot notation` to "reach
65-
into" embedded documents. See :ref:`query for data in arrays
66-
<read-operations-arrays>` and :ref:`query data in embedded documents
67-
<read-operations-embedded-documents>` for more examples on accessing data in
68-
arrays and embedded documents.
66+
Embedded Data Model and Deprecated MMAPv1
67+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68+
69+
Embedding related data in documents may lead to situations where
70+
documents grow after creation. With the deprecated MMAPv1 storage
71+
engine, document growth can impact write performance and lead to data
72+
fragmentation.
73+
74+
Starting in version 3.0.0, MongoDB uses :ref:`power-of-2-allocation` as
75+
the default allocation strategy for MMAPv1 in order to account for
76+
document growth, minimizing the likelihood of data fragmentation. See
77+
:ref:`power-of-2-allocation` for details.
6978

7079
.. _data-modeling-referencing:
7180

source/core/data-model-operations.txt

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,78 +10,47 @@ Operational Factors and Data Models
1010
:depth: 1
1111
:class: singlecol
1212

13-
Modeling application data for MongoDB depends on both the data itself,
14-
as well as the characteristics of MongoDB itself. For example,
15-
different data models may allow applications to use more efficient
16-
queries, increase the throughput of insert and update operations, or
17-
distribute activity to a sharded cluster more effectively.
18-
19-
These factors are *operational* or address requirements that arise
20-
outside of the application but impact the performance of MongoDB based
21-
applications. When developing a data model, analyze all of your
22-
application's :doc:`read and write operations </crud>` in conjunction
23-
with the following considerations.
13+
Modeling application data for MongoDB should consider various
14+
operational factors that impact the performance of MongoDB. For
15+
instance, different data models can allow for more efficent queries,
16+
increase the throughput of insert and update operations, or distribute
17+
activity to a sharded cluster more effectively.
2418

25-
.. _data-model-document-growth:
26-
27-
Document Growth
28-
---------------
29-
30-
.. versionchanged:: 3.0.0
31-
32-
Some updates to documents can increase the size of documents. These
33-
updates include pushing elements to an array (i.e. :update:`$push`) and
34-
adding new fields to a document.
35-
36-
When using the MMAPv1 storage engine, document growth can be a
37-
consideration for your data model. For MMAPv1, if the document size
38-
exceeds the allocated space for that document, MongoDB will relocate
39-
the document on disk. With MongoDB 3.0.0, however, the default use of
40-
the :ref:`power-of-2-allocation` minimizes the occurrences of such
41-
re-allocations as well as allows for the effective reuse of the freed
42-
record space.
43-
44-
When using MMAPv1, if your applications require updates that will
45-
frequently cause document growth to exceeds the current power of 2
46-
allocation, you may want to refactor your data model to use references
47-
between data in distinct documents rather than a denormalized data
48-
model.
49-
50-
You may also use a *pre-allocation* strategy to explicitly avoid
51-
document growth. Refer to the :ecosystem:`Pre-Aggregated Reports Use
52-
Case </use-cases/pre-aggregated-reports>` for an example of the
53-
*pre-allocation* approach to handling document growth.
54-
55-
See :doc:`/core/mmapv1` for more information on MMAPv1.
19+
When developing a data model, analyze all of your application's
20+
:doc:`read and write operations </crud>` in conjunction with the
21+
following considerations.
5622

5723
.. _data-model-atomicity:
5824
.. _data-modeling-atomicity:
5925

6026
Atomicity
6127
---------
6228

63-
In MongoDB, operations are atomic at the :term:`document` level. No
64-
**single** write operation can change more than one document.
65-
Operations that modify more than a single document in a collection
66-
still operate on one document at a time. [#record-atomicity]_ Ensure
67-
that your application stores all fields with atomic dependency
68-
requirements in the same document. If the application can tolerate
69-
non-atomic updates for two pieces of data, you can store these data in
70-
separate documents.
71-
72-
A data model that embeds related data in a single document
73-
facilitates these kinds of atomic operations. For data models that
74-
store references between related pieces of data, the application must
75-
issue separate read and write operations to retrieve and modify these
76-
related pieces of data.
29+
In MongoDB, a write operation is atomic on the level of a single
30+
document, even if the operation modifies multiple embedded documents
31+
*within* a single document. When a single write operation modifies
32+
multiple documents (e.g. :method:`db.collection.updateMany()`), the
33+
modification of each document is atomic, but the operation as a whole
34+
is not atomic.
35+
36+
Embedded Data Model
37+
~~~~~~~~~~~~~~~~~~~
38+
39+
The embedded data model combines all related data in a single document
40+
instead of normalizing across multiple documents and collections. This
41+
data model facilitates atomic operations.
7742

7843
See :ref:`data-modeling-atomic-operation` for an example data model
7944
that provides atomic updates for a single document.
8045

81-
.. [#record-atomicity] Document-level atomic operations include all
82-
operations within a single MongoDB document record: operations that
83-
affect multiple embedded documents within that single record are still
84-
atomic.
46+
Multi-Document Transaction
47+
~~~~~~~~~~~~~~~~~~~~~~~~~~
48+
49+
For data models that store references between related
50+
pieces of data, the application must issue separate read and write
51+
operations to retrieve and modify these related pieces of data.
52+
53+
.. include:: /includes/extracts/transactions-intro.rst
8554

8655
Sharding
8756
--------
@@ -305,3 +274,36 @@ documents, consider :doc:`/core/capped-collections`. Capped collections
305274
provide *first-in-first-out* (FIFO) management of inserted documents
306275
and efficiently support operations that insert and read documents based
307276
on insertion order.
277+
278+
.. _data-model-document-growth:
279+
280+
Document Growth and MMAPv1
281+
--------------------------
282+
283+
.. versionchanged:: 3.0.0
284+
285+
Some updates to documents can increase the size of documents. These
286+
updates include pushing elements to an array (i.e. :update:`$push`) and
287+
adding new fields to a document.
288+
289+
When using the deprecated MMAPv1 storage engine, document growth can be
290+
a consideration for your data model. For MMAPv1, if the document size
291+
exceeds the allocated space for that document, MongoDB will relocate
292+
the document on disk. Starting with MongoDB 3.0, however, the default
293+
use of the :ref:`power-of-2-allocation` minimizes the occurrences of
294+
such re-allocations as well as allows for the effective reuse of the
295+
freed record space.
296+
297+
When using MMAPv1, if your applications require updates that will
298+
frequently cause document growth to exceeds the current power of 2
299+
allocation, you may want to refactor your data model to use references
300+
between data in distinct documents rather than a denormalized data
301+
model.
302+
303+
You may also use a *pre-allocation* strategy to explicitly avoid
304+
document growth. Refer to the :ecosystem:`Pre-Aggregated Reports Use
305+
Case </use-cases/pre-aggregated-reports>` for an example of the
306+
*pre-allocation* approach to handling document growth.
307+
308+
See :doc:`/core/mmapv1` for more information on MMAPv1.
309+

source/core/data-modeling-introduction.txt

Lines changed: 73 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,46 @@ Data Modeling Introduction
1010
:depth: 1
1111
:class: singlecol
1212

13-
Data in MongoDB has a *flexible schema*. Unlike SQL databases, where
14-
you must determine and declare a table's schema before inserting data,
15-
MongoDB's :term:`collections <collection>` do not enforce
16-
:term:`document` structure. This flexibility facilitates the mapping of
17-
documents to an entity or an object. Each document can match the data
18-
fields of the represented entity, even if the data has substantial
19-
variation. In practice, however, the documents in a collection share a
20-
similar structure.
21-
2213
The key challenge in data modeling is balancing the needs of the
2314
application, the performance characteristics of the database engine, and
2415
the data retrieval patterns. When designing data models, always
2516
consider the application usage of the data (i.e. queries, updates, and
2617
processing of the data) as well as the inherent structure of the data
2718
itself.
2819

29-
Document Structure
30-
------------------
20+
Flexible Schema
21+
---------------
3122

32-
.. start-primer-excerpt
23+
Unlike SQL databases, where you must determine and declare a table's
24+
schema before inserting data, MongoDB's :term:`collections
25+
<collection>`, by default, does not require its :doc:`documents
26+
</core/document>` to have the same schema. That is:
3327

34-
The key decision in designing data models for MongoDB applications
35-
revolves around the structure of documents and how the application
36-
represents relationships between data. There are two tools that allow
37-
applications to represent these relationships: *references* and
38-
*embedded documents*.
28+
- The documents in a single collection do not need to have the same set
29+
of fields and the data type for a field can differ across documents
30+
within a collection.
3931

40-
References
41-
~~~~~~~~~~
32+
- To change the structure of the documents in a collection, such as add
33+
new fields, remove existing fields, or change the field values to a
34+
new type, update the documents to the new structure.
4235

43-
References store the relationships between data by including
44-
links or *references* from one document to another. Applications can
45-
resolve these :doc:`references </reference/database-references>` to
46-
access the related data. Broadly, these are *normalized* data models.
36+
This flexibility facilitates the mapping of documents to an entity or
37+
an object. Each document can match the data fields of the represented
38+
entity, even if the document has substantial variation from other
39+
documents in the collection.
4740

48-
.. include:: /images/data-model-normalized.rst
41+
In practice, however, the documents in a collection share a similar
42+
structure, and you can enforce :doc:`document validation rules
43+
</core/schema-validation>` for a collection during update and insert
44+
operations. See :doc:`/core/schema-validation` for details.
4945

50-
See :ref:`data-modeling-referencing` for the strengths and weaknesses of
51-
using references.
46+
Document Structure
47+
------------------
48+
49+
The key decision in designing data models for MongoDB applications
50+
revolves around the structure of documents and how the application
51+
represents relationships between data. MongoDB allows related data to
52+
be embedded within a single document.
5253

5354
Embedded Data
5455
~~~~~~~~~~~~~
@@ -62,42 +63,46 @@ database operation.
6263

6364
.. include:: /images/data-model-denormalized.rst
6465

66+
For many use cases in MongoDB, the denormalized data model is optimal.
67+
6568
See :ref:`data-modeling-embedding` for the strengths and weaknesses of
6669
embedding documents.
6770

68-
.. end-primer-excerpt
71+
References
72+
~~~~~~~~~~
73+
74+
References store the relationships between data by including
75+
links or *references* from one document to another. Applications can
76+
resolve these :doc:`references </reference/database-references>` to
77+
access the related data. Broadly, these are *normalized* data models.
78+
79+
.. include:: /images/data-model-normalized.rst
80+
81+
See :ref:`data-modeling-referencing` for the strengths and weaknesses of
82+
using references.
6983

7084
Atomicity of Write Operations
7185
-----------------------------
7286

73-
In MongoDB, write operations are atomic at the :term:`document` level,
74-
and no single write operation can atomically affect more than one
75-
document or more than one collection. A denormalized data model with
76-
embedded data combines all related data for a represented entity in a
77-
single document. This facilitates atomic write operations since a
78-
single write operation can insert or update the data for an entity.
79-
Normalizing the data would split the data across multiple collections
80-
and would require multiple write operations that are not atomic
81-
collectively.
82-
83-
However, schemas that facilitate atomic writes may limit ways that
84-
applications can use the data or may limit ways to modify applications.
85-
The :ref:`Atomicity Considerations <data-model-atomicity>`
86-
documentation describes the challenge of designing a schema that
87-
balances flexibility and atomicity.
88-
89-
Document Growth
90-
---------------
87+
Single Document Atomicity
88+
~~~~~~~~~~~~~~~~~~~~~~~~~
9189

92-
Some updates, such as pushing elements to an array or adding new
93-
fields, increase a :term:`document's <document>` size.
90+
In MongoDB, a write operation is atomic on the level of a single
91+
document, even if the operation modifies multiple embedded documents
92+
*within* a single document.
93+
94+
A denormalized data model with embedded data combines all related data
95+
in a single document instead of normalizing across multiple documents
96+
and collections. This data model facilitates atomic operations.
97+
98+
.. include:: /includes/extracts/concurrent-operations-multi-document-writes.rst
9499

95-
For the MMAPv1 storage engine, if the document size exceeds the
96-
allocated space for that document, MongoDB relocates the document on
97-
disk. When using the MMAPv1 storage engine, growth consideration can
98-
affect the decision to normalize or denormalize data. See
99-
:ref:`Document Growth Considerations <data-model-document-growth>` for
100-
more about planning for and managing document growth for MMAPv1.
100+
Multi-Document Transactions
101+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
102+
103+
.. include:: /includes/extracts/transactions-intro.rst
104+
105+
.. seealso:: :ref:`Atomicity Considerations <data-model-atomicity>`
101106

102107
Data Use and Performance
103108
------------------------
@@ -110,3 +115,18 @@ adding indexes to support common queries can improve performance.
110115

111116
See :doc:`/core/data-model-operations` for more information on these
112117
and other operational considerations that affect data model designs.
118+
119+
Document Growth and MMAPv1
120+
--------------------------
121+
122+
Some updates, such as pushing elements to an array or adding new
123+
fields, increase a :term:`document's <document>` size.
124+
125+
For the :doc:`deprecated MMAPv1 </core/mmapv1>` storage engine, if the
126+
document size exceeds the allocated space for that document, MongoDB
127+
relocates the document on disk. When using the deprecated MMAPv1
128+
storage engine, growth consideration can affect the decision to
129+
normalize or denormalize data. See :ref:`Document Growth Considerations
130+
<data-model-document-growth>` for more about planning for and managing
131+
document growth for MMAPv1.
132+

source/core/inmemory.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ Write operations that specify a write concern :writeconcern:`journaled
134134
shuts down, either as result of the :dbcommand:`shutdown` command or
135135
due to a system error, recovery of in-memory data is impossible.
136136

137+
Transactions
138+
------------
139+
140+
Multi-document transactions are not available for deployments with
141+
members that use in-memory storage engine.
142+
137143
Deployment Architectures
138144
------------------------
139145

0 commit comments

Comments
 (0)