1

I have a document just like this.

{ "Node": { "-name": "Dev6", "Interface": [ { "-ip": "10.20.18.65", "-mask": "255.255.255.192" }, { "-ip": "10.20.18.129", "-mask": "255.255.255.192" } ] } }

My perl program is following.

my $dbs_update_Node_by_key ='FOR u IN Node FILTER u._key == @key  UPDATE u WITH {
    name: @name,
    Interface: @Interface
} IN Node';

...... 
(comments: $inf means [{"-ip","-mask"},{"-ip","-mask"}])

my $bind_args = {
key => $doc->{'_key'},
name => $node_attrs->{'-name'},
Interface => $inf
};

$sth = $itdb->query($dbs_update_Node_by_key)->bind($bind_args)->execute();

It returns "Invalid bind parameter value". I think ArangoDB perl driver didn't support it. How can I use AQL or REST API to implement it? Thanks!

1 Answer 1

1

I think the problem is that

[{"-ip","-mask"},{"-ip","-mask"}]

won't work. When using the curly brackets and member names (e.g. "-ip", "-mask"), there must be a value associated to each member. Using this value instead should work:

[{"-ip": "a.b.c.d", "-mask": "a.b.c.d" }, {"-ip": "a.b.c.d" ,"-mask": "a.b.c.d" }]

Please also note that in your above query, you will update an attribute named "name", whereas in the example document the attribute name is "-name" (with minus sign in front). To use an attribute name with a minus sign at the beginning, it needs to be quoted in backticks in AQL (see below).

Additionally, the example document has attributes "-name" and "Interface" inside a sub-attribute "Node", whereas the UPDATE command will update attributes "name" and "Interface" on the top level of the document.

I have adjusted the query a bit. The following sequence seems to work from the ArangoShell:

db._create("Node"); 
db.Node.save({ 
  "_key": "test", 
  "Node": { 
    "someAttribute": "someValue", 
    "-name": "Dev6",  
    "Interface": [ 
      { 
        "-ip": "10.20.18.65", 
        "-mask": "255.255.255.192" 
      }, 
      { 
        "-ip": "10.20.18.129", 
        "-mask": "255.255.255.192" 
      } 
    ] 
  } 
}); 

dbs_update_Node_by_key = 'FOR u IN Node FILTER u._key == @key ' +
  'UPDATE u WITH { Node: { `-name`: @name, Interface: @Interface } } IN Node'; 

bind_args = { 
  key: "test", 
  name: "Dev8", 
  Interface: [
    {
      "-ip": "8.8.8.8", 
      "-mask": "255.255.255.192" 
    }, 
    {
      "-ip": "192.168.0.1",
      "-mask": "255.255.255.255" 
    }
  ] 
}; 

db._query(dbs_update_Node_by_key, bind_args); 
db.Node.toArray();

This will produce:

[ 
  { 
    "_id" : "Node/test", 
    "_key" : "test", 
    "_rev" : "18996044030550", 
    "Node" : { 
      "-name" : "Dev8", 
      "someAttribute" : "someValue", 
      "Interface" : [ 
        { 
          "-ip" : "8.8.8.8", 
          "-mask" : "255.255.255.192" 
        }, 
        { 
          "-ip" : "192.168.0.1", 
          "-mask" : "255.255.255.255" 
        } 
      ] 
    } 
  } 
]

I am not sure if this is what you required, but at least it updates the document and overwrites the "Interface" attribute with new values.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I have solved it according to you advice. BTW, I think "-" isn't suitable for AQL. For example: 'FOR u IN Node FILTER u.-AdminIP == @AdminIP RETURN u' can't be parsed by AQL.
yes, attribute names starting with a minus sign need to be enclosed in backticks in order to be parsed properly in AQL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.