How to query attributes with spaces in their names

Viewed 80

Probably a silly question, but if in a collection I have documents which include attributes defined with spaces, example:

{
 "attribute with spaces" : "blabla",
 ...
}

How can I query for finding it? I tried

for document in documents
    filter document."attribute with spaces" == "blabla"

But of course I get a syntax error.

1 Answers

Attribute names that are reserved keywords or contain spaces or other characters not allowed in attribute names must be quoted with backticks:

FOR document IN documents
    FILTER document.`attribute with spaces` == "blabla"

Alternatively you can use attribute access like this:

FOR document IN documents
    FILTER document["attribute with spaces"] == "blabla"

This is also explained in the documentation: https://www.arangodb.com/docs/stable/aql/fundamentals-syntax.html#names

Related