ArangoDB query attribute embedded in list
I have a document embedded in a list and I need to query documents that match the value of a series of strings.
My doc:
As you can see, I have a regular document. Within this document are "categories" that are of unknown length for each document. Within the categories, I have "trust" and "title". I need to query to find documents that have titles that match the list of titles I have in the ArrayList. The query I thought would work:
FOR document IN documents FILTER document.categories.title IN @categories RETURN article
@categories is an ArrayList with a list of titles. If any of the headers in the ArrayList are in the document, I would like it to be returned.
This request returns null
. I don't think it gets to the point of comparing ArrayList to the "title" field in my document. I know I can access the list of categories with [#]
, but I don't know how to search for "titles" in "categories".
source to share
Request
FOR document IN documents
FILTER document.categories.title IN @categories
RETURN article
will work if document.categories
is a scalar, but it won't work if document.categories
is an array. The reason is that the array on the left side of the statement IN
will not be automatically expanded.
To find documents, the query can be rewritten as follows:
FOR document IN documents
FILTER document.categories[*].title IN @categories
RETURN document
or
FOR document IN documents
LET titles = (
FOR category IN document.categories
RETURN category.title
)
FILTER titles IN @categories
RETURN document
Also, it article
will be unknown if the named collection does not exist article
. He should probably read document
or document.article
.
source to share