SELECT
the select operation, once executed, retrieves documents from a collection and uses clauses like where to specify conditions for filtering the documents to return dql currently only supports the select operation for document retrieval with select , all responses result in full documents expect more advanced select capabilities in upcoming dql releases for more information, see docid\ flhqlsnmxghek5lfojd b select statements the following syntax outlines the basic structure and optional clauses you can use within your select statements to specify your conditions for retrieval dql select from your collection name \[where condition] \[order by orderby expression 1, orderby expression 2, \[asc|desc]] \[limit limit value] \[offset number of documents to skip] for instance, retrieve all documents in the cars collection where the color property is set to the value 'blue' 'blue' dql select from cars where color = 'blue' to perform a select and receive all document fields, including an embedded map dql select from collection your collection name (field1 map, field2 attachment) clauses for filtering the following table provides an overview of the different clauses you can use to define specific conditions and calculations within your dql select statements to provide more granular control over your queries clause description from from the required clause specifying the collection containing the documents for retrieval (see /#from ) where where applies filtering conditions to restrict the documents included in the result set (see /#where ) order by order by s pecifies the sorting order of the result set based on one or more expressions (see /#order by ) limit limit restricts the number of documents included in the result set (see /#limit ) offset offset skips a specific number of documents before returning the result set (see /#offset ) from required in each select statement you write in dql, the from element identifies the collection for document retrieval dql select from your collection name for example, a select statement querying documents from the cars collection dql select from cars where the where clause filters data based on either an expression or a set of conditions that narrow the result set returned to you dql select from your collection name where \[condition] for example, here is a basic select statement querying documents from the cars collection based on a given address dql select from cars where location address = '123 main st, san francisco, ca 98105' to demonstrate a more complex query, here is a select statement that queries using multiple expressions and logical operators to further refine the criteria for document retrieval dql select from cars where color = 'blue' and features trim = 'standard' or features mileage > 10000 order by with the order by clause, if you'd like, you can integrate calculations or expressions in your select statement then sort the resulting documents to return in either ascending ( asc ) or descending ( desc ) alphabetical order dql select from your collection name order by expression 1, expression 2, \[asc|desc] for example, here is a simple select statement that uses the order by clause to query and sort documents from the cars collection in descending ( desc ) alphabetical order based on the field value set for the color property dql select from cars order by color desc in this syntax your collection name is the name of the collection from which you want to retrieve the data expression 1, expression 2, are the expressions evaluated to sort the result expressions are resolved in order \[asc|desc] is an optional parameter that specifies the sort order if omitted, the default sort order is ascending ( asc ) to sort in descending order, you can specify desc example in this example, the result set from the query will be sorted in descending order based on the values in the field dql sort by a given field name select from your collection name order by field name desc for instance, here "blue" cars return first and other cars sort by the natural order in the collection dql select from cars order by color = 'blue' sort order by object type in dql, the hierarchy for comparing and sorting objects varies based on the following criteria if ascending ( asc ) order operations boolean number binary string array object null missing if descending ( desc ) order operations, sorting order is reversed missing null object array string binary number boolean if evaluating values, true results are prioritized and ordered first followed by false results expressing sort order unless explicitly defined as desc in your query, ditto defaults to sorting in ascending ( asc ) so, if you want to sort in ascending order, you do not have to express that in your query limit the limit clause is used to restrict the number of documents returned by a query, allowing you to specify a maximum limit on the number of documents to be included in the result set dql select from your collection name limit limit value in this syntax your collection name is the name of the collection from which you want to retrieve the data limit value is the maximum number of documents you want to include in the result set for example, o nly return the first 10 documents from the your collection name collection dql select from your collection name limit 10 offset the offset clause is used to specify the number of records to skip before starting to return documents from the query result dql select from your collection name offset number of items to skip in this syntax your collection name is the name of the collection from which you want to retrieve the data number of items to skip is the number of items before returning the result set using offset with limit is a common way to utilize offset ; for example dql select from your collection name limit 10 offset 10