当我使用 AQL 将文档插入到集合中时,它返回一个空列表。
arangosh [test]> db._query('INSERT @document INTO vertices', {document: {name: "bar"}}).toArray()
[ ]
有没有办法插入文档并在单个 AQL 查询中获取完整文档?
我希望得到的是:
{
"_id": "vertices/641272433780",
"_key": "641272433780",
"_rev": "641272433780",
"name": "bar"
}
最佳答案
从 ArangoDB 2.4 开始,这是可能的。返回创建的文档,原始查询
INSERT @document INTO vertices
必须改为
INSERT @document INTO vertices LET result = NEW RETURN result
这也适用于多文档插入以及更新/替换和删除。以下引述自2.4 documentation描述语法:
To return documents from a data-modification query, the INSERT, REMOVE, UPDATE or REPLACE statement must be immediately followed by a LET statement that assigns either the pseudo-value NEW or OLD to a user-defined variable. The LET statement must be followed by a RETURN statement that returns the variable introduced by LET.
NEW refers to the inserted or modified document revision, and OLD refers to the document revision before update or removal. INSERT statements can only refer to the NEW pseudo-value, and REMOVE operations only to OLD. UPDATE and REPLACE can refer to either.
关于arangodb - 在单个 AQL 查询中插入并返回文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27788089/