如何从php中的arangodb事务返回值?

时间:2018-07-14 17:15:36

标签: php transactions arangodb

我正在尝试通过以下交易返回创建的密钥:

$trans=new Transaction($connection,array( 'collections' => array( 'write' => array( 'users','group_relations','groups' ),'read'=> array( 'users','group_relations','groups' ) ), 'waitForSync' => true ));
        $trans->setAction('function(){
            var db= require("@arangodb").db;
            var ids = []; 
            db.groups.insert([{"name":"'.$name.'","type":"'.$type.'","restriction":"'.$restriction.'","picture":"'.$picture.'"}]).forEach(
              function(obj) {ids.push(obj._key);});
            db.group_relations.insert({"_from":"users/'.$_SESSION['uid'].'","_to":"groups/"+ids["0"],"status":"admin"});
            return ids["0"];
        }');
       echo $trans->execute();

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

从文档中:

/**
147      * Execute the transaction
148      *
149      * This will post the query to the server and return the results as
150      * a Cursor. The cursor can then be used to iterate the results.
151      *
152      * @throws Exception throw exception if transaction failed
153      * @return mixed true if successful without a return value or the return value if one was set in the action
154      */

只需分配值即可。