wrong _rev for update or replace does not lead to an error

13 views
Skip to first unread message

Martin Kuhn

unread,
Aug 19, 2016, 6:26:22 AM8/19/16
to ArangoDB
Hi, 

I try out transaction handling where I do only a simple replace operation on 2 documents in 2 different collections.

When I pass in an outdated "_rev" I get NO error

What could be the reason for this?

e.g.
    function () {
        // This code will be executed inside ArangoDB!
        var db = require('org/arangodb').db;
        
        var payment = db.payment.replace(params['payment']._key, params['payment'], {rev: 1083175989924});
        var notification = db.paymentnotification.replace(params['notification']._key, params['notification'], {rev: 1083175989931});
        return {notification: notification, payment: payment};
        
      }

Can anybody give me a hint?
TIA

Martin Kuhn

unread,
Aug 19, 2016, 9:20:43 AM8/19/16
to ArangoDB
Also a simple test with arangosh really confuses me:

In the following sequence, the last update should bring an error

db.testi.save({_key: "123", city: "ABC"})
result:
{
  "_id" : "testi/123",
  "_key" : "123",
  "_rev" : "1083175598030"
}

db.testi.update("123", { city: "CDEF"})
result:
{
  "_id" : "testi/123",
  "_key" : "123",
  "_rev" : "1083175598070",
  "_oldRev" : "1083175598030"
}

// here I try an update with an outdated rev -> this should not be successfull, right?
db.testi.update("123", { city: "XYZ"},"1083175598030")
result:
{
  "_id" : "testi/123",
  "_key" : "123",
  "_rev" : "1083175598101",
  "_oldRev" : "1083175598070"
}

Jan

unread,
Aug 19, 2016, 9:25:05 AM8/19/16
to ArangoDB
Hi Martin,

AFAIK the revision number for version checking should not be specified as the third parameter to update()


    db.testi.update("123", { city: "XYZ"},"1083175598030")

but as part of the search value:

    db.testi.update({ _key: "123", _rev:"1083175598030", { city: "XYZ"})

That should trigger a conflict should the actual revision number differ.
I think the third parameter to update() can be used to provide extra options, but is not used for revision number checking.

Best regards
Jan

Jan

unread,
Aug 19, 2016, 9:26:28 AM8/19/16
to ArangoDB
Hi again,

sorry in my example I missed a closing curly bracket. It should of course be:


db.testi.update({ _key: "123", _rev:
"1083175598030" }, { city: "XYZ"})

Best regards
Jan


Martin Kuhn

unread,
Aug 19, 2016, 9:51:21 AM8/19/16
to ArangoDB
Hi Jan,

oh thank you, this works. I used the API descripton from arangojs which is different (it is a little bit confusing that the API differs)

Is there a reference of the API which can be used for running in the server?

TIA

Jan

unread,
Aug 19, 2016, 11:15:44 AM8/19/16
to ArangoDB
Hi,

I found the docs for the server methods here:

https://docs.arangodb.com/3.0/Manual/DataModeling/Documents/DocumentMethods.html#update

in the section "Update":
collection.update(selector, data)

Updates an existing document described by the selector, which must be an object containing the _id or _key attribute. There must be a document with that _id or _key in the current collection. This document is then patched with the data given as second argument. Any attribute _id, _key or _rev in data is ignored.

The method returns a document with the attributes _id, _key, _rev and _oldRev. The attribute _id contains the document handle of the updated document, the attribute _rev contains the document revision of the updated document, the attribute _oldRev contains the revision of the old (now updated) document.

If the selector contains a _rev attribute, the method first checks that the specified revision is the current revision of that document. If not, there is a conflict, and an error is thrown.


Best regards
Jan

Martin Kuhn

unread,
Aug 20, 2016, 1:55:24 AM8/20/16
to ArangoDB
Great, thank you very much!
Reply all
Reply to author
Forward
0 new messages