Question

As shown blow,sometime,the elements of embedded array comments will be modified,or an new comment will be inserted into comments as first element,and when these modifications happen,I want to lock something in minimal scope to avoid nasty issue,questions are:

1,What scope to lock is appropriate?
2,How to lock?


{
    name: 'Me',
    comments: [{
    "author": "Joe S.",
    "text": "I'm Thirsty"
  },
  {
    "author": "Adder K.",
    "text":  "old content"
  }]
}
Was it helpful?

Solution

RethinkDB automatically locks the document when you do an update, so concurrent modifications to the embedded comments array should not be an issue.

Whether you need additional locking depends on your application and the structure of your data. For example, is one of the fields in the embedded comments a reference to a different document, which must be maintained?

OTHER TIPS

RethinkDB provides an atomicity per document (see http://www.rethinkdb.com/docs/advanced-faq/#how-does-the-atomicity-model-work).

So you can update a nested array (push/update/delete an element in the array) without having to worry about a concurrent operation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top