Moo
Moo

Reputation: 97

ArangoDB lastinsert-Value is NULL

My Query:

I would insert 2 Datasets on 2 Collections with lastInsert 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._key, "user_key": @User_key} IN xinhalt

Result:

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

Why is i._keyNULL?

Winke winke

Upvotes: 0

Views: 191

Answers (1)

mpv89
mpv89

Reputation: 1891

The result i of your subquery is from type array not document. Every query result in AQL is from type array (see docs).

You have to write i[0]._key instead of i._key within your second INSERT.

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

Upvotes: 0

Related Questions