-1

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"
  }]
}
Alex Luya
  • 9,412
  • 15
  • 59
  • 91

2 Answers2

3

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?

Daniel Mewes
  • 1,876
  • 14
  • 16
1

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.

neumino
  • 4,342
  • 1
  • 18
  • 17
  • I don't think this is right,what about if I need retrieve the array,do some comparison,then do insertion? – Alex Luya Dec 10 '13 at 09:01