- Query operation parameters
- Executing simple query
- Executing query with bind variables
- Executing non-query operation
- Result format options
- Parse query
- Minify query
- Delete cursor
- More examples
Query operations are focused on executing and analyzing AQL queries. These operations are accessible through Query
property in database context object.
Applicable parameters available through fluent API:
Aql(string query)
- Sets AQL query code.BindVar(string key, object value)
- Maps key/value bind parameter.Count(bool value)
- Determines whether the number of retrieved documents should be returned inExtra
property ofAResult
instance. Default value: false.Ttl(int value)
- Determines whether the number of documents in the result set should be returned. Default value: false.BatchSize(int value)
- Determines maximum number of result documents to be transferred from the server to the client in one roundtrip. If not set this value is server-controlled.
var db = new ADatabase("myDatabaseAlias");
var queryResult = db.Query
.Aql(@"
FOR item IN MyDocumentCollection
RETURN item
")
.ToDocuments();
if (queryResult.Success)
{
foreach (var document in queryResult.Value)
{
var foo = document.String("foo");
var bar = document.Int("bar");
}
}
var db = new ADatabase("myDatabaseAlias");
var queryResult = db.Query
.BindVar("bar", 123)
.Aql(@"
FOR item IN MyDocumentCollection
FILTER item.bar == @bar
RETURN item
")
.ToDocuments();
if (queryResult.Success)
{
foreach (var document in queryResult.Value)
{
var foo = document.String("foo");
var bar = document.Int("bar");
}
}
Result of the non-query operation does not contain value information and is intended for queries that do not return any data.
var db = new ADatabase("myDatabaseAlias");
var queryResult = db.Query
.Aql(@"
UPSERT { bar: 1 }
INSERT { foo: 'some string value', bar: 1 }
UPDATE { foo: 'some string value updated', bar: 2 }
IN MyCollection
")
.ExecuteNonQuery();
if (queryResult.Success)
{
// operation executed successfuly with queryResult.HasValue == false and queryResult.Value == null
}
Query result can be retrieved through following methods with different value type:
ToDocuments()
- Retrieves result value as list of documents.ToList<T>()
- Retrieves result value as list of generic objects.ToList()
- Retrieves result value as list of objects.ToDocument()
- Retrieves result value as single document.ToObject<T>()
- Retrieves result value as single generic object.ToObject()
- Retrieves result value as single object.
Analyzes specified AQL query.
var db = new ADatabase("myDatabaseAlias");
var parseQueryResult = db.Query.Parse("FOR item IN MyDocumentCollection RETURN item");
if (parseQueryResult.Success)
{
var analyzedQueryDocument = parseQueryResult.Value;
}
Transforms specified query into minified version with removed leading and trailing whitespaces except new line characters.
var singleLineQuery = AQuery.Minify(@"
FOR item IN MyDocumentCollection
RETURN item
");
Deletes specified AQL query cursor.
var db = new ADatabase("myDatabaseAlias");
var deleteCursorResult = db.Query
.DeleteCursor("someCursorID");
if (deleteCursorResult.Success)
{
var isCursorDeleted = deleteCursorResult.Value;
}
More examples regarding AQL query operations can be found in unit tests.