<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Storage Strategies — Doctrine MongoDB ODM 1.1.5 documentation</title> <link rel="stylesheet" href="../_static/bootstrap/css/bootstrap.min.css" type="text/css" /> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/layout.css" type="text/css" /> <link rel="stylesheet" href="../_static/configurationblock.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '1.1.5', COLLAPSE_MODINDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/configurationblock.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/configurationblock.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/configurationblock.js"></script> <script src="../_static/bootstrap/js/bootstrap.min.js"></script> <script type="text/javascript"> <!-- $(document).ready(function() { $("#versions").change(function() { var docsUrl = $(this).val(); window.location.href = docsUrl; }); }); --> </script> <link rel="shortcut icon" href="../_static/doctrine.ico"/> <link rel="search" title="Search" href="../search.html" /> <link rel="top" title="Doctrine MongoDB ODM 1.1.5 documentation" href="../index.html" /> </head> <body> <div id="wrapper"> <div id="header"> <h1 id="h1title"></h1> <div id="logo"> <a href="http://www.doctrine-project.org/">Doctrine - PHP Database Libraries</a> </div> </div> <div id="nav" class="cls"> <div class="tl cls"> <ul> <li><a target="_top" href="http://www.doctrine-project.org/">Home</a></li> <li><a target="_top" href="http://www.doctrine-project.org/about.html">About</a></li> <li><a target="_top" href="http://www.doctrine-project.org/projects.html">Projects</a></li> <li><a target="_top" href="http://www.doctrine-project.org/contribute.html">Contribute</a></li> <li><a target="_top" href="http://www.doctrine-project.org/community.html">Community</a></li> <li><a target="_top" href="http://www.doctrine-project.org/archive.html">Blog</a></li> <li><a target="_top" href="http://www.doctrine-project.org/jira">Development</a></li> </ul> </div> </div> <div id="content" class="cls"> <div class="related"> <h3>Navigation</h3> <ul> <li><a href="/">Doctrine Homepage</a> »</li> <li><a href="../index.html">Doctrine MongoDB ODM 1.1.5 documentation</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" > <div class="section" id="storage-strategies"> <span id="id1"></span><h1>Storage Strategies<a class="headerlink" href="#storage-strategies" title="Permalink to this headline">¶</a></h1> <p>Doctrine MongoDB ODM implements several different strategies for persisting changes to mapped fields. These strategies apply to the following mapping types:</p> <ul class="simple"> <li><span class="xref std std-ref">int</span></li> <li><span class="xref std std-ref">float</span></li> <li><a class="reference internal" href="embedded-mapping.html#embed-many"><span class="std std-ref">Embed Many</span></a></li> <li><a class="reference internal" href="reference-mapping.html#reference-many"><span class="std std-ref">Reference Many</span></a></li> </ul> <p>For collections, Doctrine tracks changes via the PersistentCollection class. The strategies described on this page are implemented by the CollectionPersister class. The <code class="docutils literal"><span class="pre">increment</span></code> strategy cannot be used for collections.</p> <div class="section" id="increment"> <h2>increment<a class="headerlink" href="#increment" title="Permalink to this headline">¶</a></h2> <p>The <code class="docutils literal"><span class="pre">increment</span></code> strategy does not apply to collections but can be used for <code class="docutils literal"><span class="pre">int</span></code> and <code class="docutils literal"><span class="pre">float</span></code> fields. When using the <code class="docutils literal"><span class="pre">increment</span></code> strategy, the field value will be updated using the <a class="reference external" href="https://docs.mongodb.com/manual/reference/operator/update/inc/">$inc</a> operator.</p> </div> <div class="section" id="addtoset"> <h2>addToSet<a class="headerlink" href="#addtoset" title="Permalink to this headline">¶</a></h2> <p>The <code class="docutils literal"><span class="pre">addToSet</span></code> strategy uses MongoDB's <a class="reference external" href="https://docs.mongodb.com/manual/reference/operator/update/addToSet/">$addToSet</a> 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 <a class="reference internal" href="#pushall">pushAll</a> strategy, elements are inserted in a separate query after removing deleted elements.</p> </div> <div class="section" id="set"> <h2>set<a class="headerlink" href="#set" title="Permalink to this headline">¶</a></h2> <p>The <code class="docutils literal"><span class="pre">set</span></code> strategy uses MongoDB's <a class="reference external" href="https://docs.mongodb.com/manual/reference/operator/update/set/">$set</a> operator to update the entire collection with a single update query.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Doctrine's Collection interface is modeled after PHP's associative arrays, so they cannot always be represented as a BSON array. If the collection's keys are not sequential integers starting with zero, the <code class="docutils literal"><span class="pre">set</span></code> strategy will store the collection as a BSON object instead of an array. Use the <a class="reference internal" href="#setarray">setArray</a> strategy if you want to ensure that the collection is always stored as a BSON array.</p> </div> </div> <div class="section" id="setarray"> <h2>setArray<a class="headerlink" href="#setarray" title="Permalink to this headline">¶</a></h2> <p>The <code class="docutils literal"><span class="pre">setArray</span></code> strategy uses MongoDB's <a class="reference external" href="https://docs.mongodb.com/manual/reference/operator/update/set/">$set</a> operator, just like the <code class="docutils literal"><span class="pre">set</span></code> strategy, but will first numerically reindex the collection to ensure that it is stored as a BSON array.</p> </div> <div class="section" id="pushall"> <h2>pushAll<a class="headerlink" href="#pushall" title="Permalink to this headline">¶</a></h2> <p>The <code class="docutils literal"><span class="pre">pushAll</span></code> strategy uses MongoDB's <a class="reference external" href="https://docs.mongodb.com/manual/reference/operator/update/pushAll/">$pushAll</a> operator to insert elements into the array. MongoDB does not allow elements to be added and removed from an array in a single operation, so this strategy relies on multiple update queries to remove and insert elements (in that order).</p> </div> <div class="section" id="atomicset"> <span id="atomic-set"></span><h2>atomicSet<a class="headerlink" href="#atomicset" title="Permalink to this headline">¶</a></h2> <p>The <code class="docutils literal"><span class="pre">atomicSet</span></code> strategy uses MongoDB's <a class="reference external" href="https://docs.mongodb.com/manual/reference/operator/update/set/">$set</a> operator to update the entire collection with a single update query. Unlike with <code class="docutils literal"><span class="pre">set</span></code> strategy there will be only one query for updating both parent document and collection itself. This strategy can be especially useful when dealing with high concurrency and <a class="reference internal" href="annotations-reference.html#annotations-reference-version"><span class="std std-ref">versioned documents</span></a>.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">The <code class="docutils literal"><span class="pre">atomicSet</span></code> and <code class="docutils literal"><span class="pre">atomicSetArray</span></code> strategies may only be used for collections mapped directly in a top-level document.</p> </div> </div> <div class="section" id="atomicsetarray"> <span id="atomic-set-array"></span><h2>atomicSetArray<a class="headerlink" href="#atomicsetarray" title="Permalink to this headline">¶</a></h2> <p>The <code class="docutils literal"><span class="pre">atomicSetArray</span></code> strategy works exactly like <code class="docutils literal"><span class="pre">atomicSet</span></code> strategy, but will first numerically reindex the collection to ensure that it is stored as a BSON array.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">The <code class="docutils literal"><span class="pre">atomicSet</span></code> and <code class="docutils literal"><span class="pre">atomicSetArray</span></code> strategies may only be used for collections mapped directly in a top-level document.</p> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <div id="searchbox" style=""> <h3>Search</h3> <form class="search" action="http://readthedocs.org/search/project/" method="get"> <input type="text" name="q" size="18"> <input type="submit" value="Go"> <input type="hidden" name="selected_facets" value="project:"> </form> </div> <h3><a href="../index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Storage Strategies</a><ul> <li><a class="reference internal" href="#increment">increment</a></li> <li><a class="reference internal" href="#addtoset">addToSet</a></li> <li><a class="reference internal" href="#set">set</a></li> <li><a class="reference internal" href="#setarray">setArray</a></li> <li><a class="reference internal" href="#pushall">pushAll</a></li> <li><a class="reference internal" href="#atomicset">atomicSet</a></li> <li><a class="reference internal" href="#atomicsetarray">atomicSetArray</a></li> </ul> </li> </ul> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/reference/storage-strategies.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> </div> <div class="clearer"></div> </div> <div class="footer"> © Copyright 2013, Doctrine Project Team. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.6.2. <br/> <a target="_BLANK" href="http://www.servergrove.com"><img src="http://www.doctrine-project.org/_static/servergrove.jpg" /></a> <br/><br/> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick" /> <input type="hidden" name="hosted_button_id" value="BAE2E3XANQ77Y" /> <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" /> <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" /> </form> </div> </div> <div id="bot-rcnr"> <div class="tl"><!-- corner --></div> </div> </div> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-288343-7"; urchinTracker(); </script> <a class="githublink" href="http://github.com/doctrine"><img src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a> </body> </html>