use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createRangeQuery.
/**
* An instance of a valid range/inequality query : range operators are limited to a single field.
*
* @return query
*/
Query createRangeQuery() {
CollectionReference cities = db.collection("cities");
// [START fs_range_query]
Query validQuery1 = cities.whereGreaterThanOrEqualTo("state", "CA").whereLessThanOrEqualTo("state", "IN");
Query validQuery2 = cities.whereEqualTo("state", "CA").whereGreaterThan("population", 1000000);
// [END fs_range_query]
return validQuery1;
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createInvalidRangeQuery.
/**
* An instance of an invalid range query : range operators are limited to a single field.
*
* @return query
*/
Query createInvalidRangeQuery() {
CollectionReference cities = db.collection("cities");
// Violates constraint : range operators are limited to a single field
// [START fs_invalid_range_query]
Query invalidRangeQuery = cities.whereGreaterThanOrEqualTo("state", "CA").whereGreaterThan("population", 100000);
// [END fs_invalid_range_query]
return invalidRangeQuery;
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createAQueryAlternate.
/**
* Creates a sample query.
*
* @return query
*/
Query createAQueryAlternate() throws Exception {
// [START fs_create_query_country]
// Create a reference to the cities collection
CollectionReference cities = db.collection("cities");
// Create a query against the collection.
Query query = cities.whereEqualTo("state", "CA");
// retrieve query results asynchronously using query.get()
ApiFuture<QuerySnapshot> querySnapshot = query.get();
for (DocumentSnapshot document : querySnapshot.get().getDocuments()) {
System.out.println(document.getId());
}
// [END fs_create_query_country]
return query;
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createOrderByNameWithLimitQuery.
/**
* Creates a query that combines order by with limit.
*
* @return query
*/
Query createOrderByNameWithLimitQuery() {
CollectionReference cities = db.collection("cities");
// [START fs_order_by_name_limit_query]
Query query = cities.orderBy("name").limit(3);
// [END fs_order_by_name_limit_query]
return query;
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createOrderByNameDescWithLimitQuery.
/**
* Creates a query that combines order by in descending order with the limit operator.
*
* @return query
*/
Query createOrderByNameDescWithLimitQuery() {
CollectionReference cities = db.collection("cities");
// [START fs_order_by_name_desc_limit_query]
Query query = cities.orderBy("name", Direction.DESCENDING).limit(3);
// [END fs_order_by_name_desc_limit_query]
return query;
}
Aggregations