Skip to content

Commit

Permalink
Document all storage strategies
Browse files Browse the repository at this point in the history
This changes the collection strategy documentation to be more generic and describe all storage strategies, regardless of whether they apply to collections or not.
  • Loading branch information
alcaeus committed Feb 7, 2016
1 parent 0d4f4ce commit b24d6af
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ Working with Objects
Advanced Topics
---------------

* **Collections**
* **Collections**:
:doc:`Capped Collections <reference/capped-collections>` |
:doc:`Collection Strategies <reference/collection-strategies>`
:doc:`Storage Strategies <reference/storage-strategies>`

* **Best Practices**:
:doc:`Best Practices <reference/best-practices>`
Expand Down
7 changes: 4 additions & 3 deletions docs/en/reference/annotations-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ Optional attributes:
-
strategy - The strategy used to persist changes to the collection. Possible
values are ``addToSet``, ``pushAll``, ``set``, and ``setArray``. ``pushAll``
is the default. See :ref:`collection_strategies` for more information.
is the default. See :ref:`storage_strategies` for more information.

.. code-block:: php
Expand Down Expand Up @@ -738,7 +738,8 @@ This is useful if many requests are attempting to update the field concurrently.
.. note::

This annotation is deprecated and will be removed in ODM 2.0. Please use the
`@Field`_ annotation with type "increment".
`@Field`_ annotation with type "int" or "float" and use the "increment"
strategy.

@Index
------
Expand Down Expand Up @@ -1196,7 +1197,7 @@ Optional attributes:
-
strategy - The strategy used to persist changes to the collection. Possible
values are ``addToSet``, ``pushAll``, ``set``, and ``setArray``. ``pushAll``
is the default. See :ref:`collection_strategies` for more information.
is the default. See :ref:`storage_strategies` for more information.

.. code-block:: php
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
.. _collection_strategies:
.. _storage_strategies:

Collection Strategies
=====================
Storage Strategies
==================

Doctrine MongoDB ODM implements four different strategies for persisting changes
to collections of embedded documents or references. These strategies apply to
the following mapping types:
Doctrine MongoDB ODM implements several different strategies for persisting changes
to mapped fields. These strategies apply to the following mapping types:

- :ref:`int`
- :ref:`float`
- :ref:`embed_many`
- :ref:`reference_many`

Internally, Doctrine tracks changes via the PersistentCollection class. The
For collections, Doctrine tracks changes via the PersistentCollection class. The
strategies described on this page are implemented by the CollectionPersister
class.
class. The ``increment`` strategy cannot be used for collections.

``addToSet``
------------
increment
---------

The ``increment`` strategy does not apply to collections but can be used for
``int`` and ``float`` fields. When using the ``increment`` strategy, the field
value will be updated using the `$inc`_ operator.

addToSet
--------

The ``addToSet`` strategy uses MongoDB's `$addToSet`_ operator to insert
elements into the array. This strategy is useful for ensuring that duplicate
values will not be inserted into the collection. Like the `pushAll`_ strategy,
elements are inserted in a separate query after removing deleted elements.

``set``
-------
set
---

The ``set`` strategy uses MongoDB's `$set`_ operator to update the entire
collection with a single update query.
Expand All @@ -37,15 +45,15 @@ collection with a single update query.
`setArray`_ strategy if you want to ensure that the collection is always
stored as a BSON array.

``setArray``
------------
setArray
--------

The ``setArray`` strategy uses MongoDB's `$set`_ operator, just like the ``set``
strategy, but will first numerically reindex the collection to ensure that it is
stored as a BSON array.

``pushAll``
-----------
pushAll
-------

The ``pushAll`` strategy uses MongoDB's `$pushAll`_ operator to insert
elements into the array. MongoDB does not allow elements to be added and removed
Expand All @@ -54,8 +62,8 @@ queries to remove and insert elements (in that order).

.. _atomic_set:

``atomicSet``
-------------
atomicSet
---------

The ``atomicSet`` strategy uses MongoDB's `$set`_ operator to update the entire
collection with a single update query. Unlike with ``set`` strategy there will
Expand All @@ -70,8 +78,8 @@ strategy can be especially useful when dealing with high concurrency and

.. _atomic_set_array:

``atomicSetArray``
------------------
atomicSetArray
--------------

The ``atomicSetArray`` strategy works exactly like ``atomicSet`` strategy, but
will first numerically reindex the collection to ensure that it is stored as a
Expand All @@ -83,6 +91,7 @@ BSON array.
collections mapped directly in a top-level document.

.. _`$addToSet`: http://docs.mongodb.org/manual/reference/operator/addToSet/
.. _`$inc`: http://docs.mongodb.org/manual/reference/operator/inc/
.. _`$pushAll`: http://docs.mongodb.org/manual/reference/operator/pushAll/
.. _`$set`: http://docs.mongodb.org/manual/reference/operator/set/
.. _`$unset`: http://docs.mongodb.org/manual/reference/operator/unset/

0 comments on commit b24d6af

Please sign in to comment.