Passing parameters to transactions

Arbitrary parameters can be passed to transactions by setting the params attribute when declaring the transaction. This feature is handy to re-use thesame transaction code for multiple calls but with different parameters.

A basic example:

  1. db._executeTransaction({
  2. collections: { },
  3. action: function (params) {
  4. return params[1];
  5. },
  6. params: [ 1, 2, 3 ]
  7. });

The above example will return 2.

Some example that uses collections:

  1. db._executeTransaction({
  2. collections: {
  3. write: "users",
  4. read: [ "c1", "c2" ]
  5. },
  6. action: function (params) {
  7. var db = require('@arangodb').db;
  8. var doc = db.c1.document(params['c1Key']);
  9. db.users.save(doc);
  10. doc = db.c2.document(params['c2Key']);
  11. db.users.save(doc);
  12. },
  13. params: {
  14. c1Key: "foo",
  15. c2Key: "bar"
  16. }
  17. });