Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The version key purpose is optimistic locking.</p> <p>When enabled, the version value is atomically incremented whenever a document is updated.</p> <p>This allow your application code to test if changes have been made between a fetch (bringing in version key 42 for example) and a consequent update (ensuring version value still is 42). If version key has a different value (eg. 43 because an update has been made to the document), your application code can handle the concurrent modification.</p> <p>The very same concept is often used in relational databases instead of pessimistic locking that can bring horrible performance. All descent ORMs provide such a feature. For example it's nicely described <a href="http://www.objectdb.com/java/jpa/persistence/lock#Optimistic_Locking_" rel="noreferrer">in ObjectDB documentation</a>. It's an object database implemented in Java but the same concept applies.</p> <p>The <a href="http://aaronheckmann.tumblr.com/post/48943525537/mongoose-v3-part-1-versioning" rel="noreferrer">blog post</a> linked in Behlül's comment demonstrate the optimistic locking usefulness with a concrete example, but only for arrays changes, see below.</p> <p>On the opposite, here is a simple case where its useless: a user profile that can be edited by its owner ownly. Here you can get rid of optimistic locking and assume that the last edit always wins.</p> <p>So, only you know if your application need optimistic locking or not. Use case by use case.</p> <p>The Mongoose situation is somewhat special.</p> <p>Optimistic locking is enabled only for arrays because the internal storage format use positional index. This is the issue described by the <a href="http://aaronheckmann.tumblr.com/post/48943525537/mongoose-v3-part-1-versioning" rel="noreferrer">blog post</a> linked in the question's comment. I found the <a href="http://grokbase.com/t/gg/mongoose-orm/137g5v9qs7/mongoose-confusion-about-versioning" rel="noreferrer">explanation</a> given in the <code>mongoose-orm</code> mailing list pretty clear: if you need optimistic locking for other fields, you need to handle it yourself.</p> <p>Here is a <a href="https://gist.github.com/bpceee/c6acb6c86f5674b91eba" rel="noreferrer">gist</a> showing how to implement a retry strategy for an <code>add</code> operation. Again, how you want to handle it depends on your use cases but it should be enough to get you started.</p> <p>I hope this clears things up.</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload