ArangoDB lastinsert-Value 为 NULL

ArangoDB lastinsert-Value is NULL

我的查询:

我将使用 lastInsert 键在 2 个集合上插入 2 个数据集。

LET i = (
INSERT {"lvl": @Lvl, "kapitel_key":@Kkey, "plan_key": @Pkey, "xcontent_key": @Xckey, "user_key": @User_key, "templatefile": @Tf } 
    IN xtemplate 
        LET inserted = NEW
            RETURN MERGE(inserted)
    )
    INSERT {"type": "text", "text": "Write here...", "xtemplate_key": i._key, "user_key": @User_key} IN xinhalt

结果:

{
  "type": "text",
  "text": "Write here...",
  "xtemplate_key": null,
  "user_key": "2345632"
}

为什么 i._keyNULL?

温克温克

您的子查询的结果 i 来自类型数组而非文档。 AQL 中的每个查询结果都来自数组类型(参见docs)。

您必须在第二个 INSERT 中写 i[0]._key 而不是 i._key

LET i = (
INSERT {"lvl": @Lvl, "kapitel_key":@Kkey, "plan_key": @Pkey, "xcontent_key": @Xckey, "user_key": @User_key, "templatefile": @Tf } 
    IN xtemplate 
        LET inserted = NEW
            RETURN MERGE(inserted)
    )
    INSERT {"type": "text", "text": "Write here...", "xtemplate_key": i[0]._key, "user_key": @User_key} IN xinhalt