Google News
logo
ArangoDB - Interview Questions
How do you perform a basic query in AQL?
Performing a basic query in AQL involves using the FOR, FILTER, and RETURN keywords to specify the data source, filtering criteria, and the fields to return in the result set. Here's a step-by-step guide to performing a basic query in AQL:

Specify the Data Source (FOR) :

* Use the FOR keyword to specify the data source from which you want to retrieve data.
* You can specify a collection, graph, or view as the data source.

Apply Filtering Criteria (FILTER) :

* Use the FILTER keyword to apply filtering criteria to the data source.
* You can filter documents based on specific conditions, such as attribute values, using comparison operators (e.g., ==, <, >, !=) and logical operators (e.g., AND, OR, NOT).

Define the Result Set (RETURN) :

* Use the RETURN keyword to specify the fields or expressions to include in the result set.
* You can return entire documents or specific fields from the documents using dot notation (e.g., doc.field).
* You can also perform calculations, transformations, or aggregations on the data before returning it.

Here's an example of a basic AQL query that retrieves all documents from a collection named "myCollection" where the value of the "status" attribute is 'active' and returns the "name" and "age" fields from each document:
FOR doc IN myCollection
    FILTER doc.status == 'active'
    RETURN { name: doc.name, age: doc.age }?

In this query :

* FOR doc IN myCollection : Specifies the data source as the "myCollection" collection.
* FILTER doc.status == 'active' : Applies a filtering condition to select only documents where the value of the "status" attribute is 'active'.
* RETURN { name: doc.name, age: doc.age } : Defines the result set to include the "name" and "age" fields from each selected document.
Advertisement