use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createAQuery.
/**
* Creates a sample query.
*
* @return query
*/
Query createAQuery() throws Exception {
// [START fs_create_query]
// Create a reference to the cities collection
CollectionReference cities = db.collection("cities");
// Create a query against the collection.
Query query = cities.whereEqualTo("capital", true);
// 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]
return query;
}
use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createSimpleQueries.
/**
* Creates queries with simple where clauses.
*
* @return queries
*/
List<Query> createSimpleQueries() {
List<Query> querys = new ArrayList<>();
CollectionReference cities = db.collection("cities");
// [START fs_simple_queries]
Query countryQuery = cities.whereEqualTo("state", "CA");
Query populationQuery = cities.whereLessThan("population", 1000000L);
Query cityQuery = cities.whereGreaterThanOrEqualTo("name", "San Francisco");
// [END fs_simple_queries]
querys.add(countryQuery);
querys.add(populationQuery);
querys.add(cityQuery);
return querys;
}
use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createOrderByCountryAndPopulation.
/**
* Creates a query that orders by country and population(descending).
*
* @return query
*/
Query createOrderByCountryAndPopulation() {
CollectionReference cities = db.collection("cities");
// [START fs_order_by_country_population]
Query query = cities.orderBy("state").orderBy("population", Direction.DESCENDING);
// [END fs_order_by_country_population]
return query;
}
use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createRangeWithOrderByQuery.
/**
* Creates a query using a range where clause with order by. Order by must be based on the same
* field as the range clause.
*
* @return query
*/
Query createRangeWithOrderByQuery() {
CollectionReference cities = db.collection("cities");
// [START fs_range_order_by_query]
Query query = cities.whereGreaterThan("population", 2500000L).orderBy("population");
// [END fs_range_order_by_query]
return query;
}
use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createEndAtFieldQueryCursor.
/**
* Create a query defining the start point of a query.
*
* @return query
*/
Query createEndAtFieldQueryCursor() {
CollectionReference cities = db.collection("cities");
// [START fs_end_at_field_query_cursor]
Query query = cities.orderBy("population").endAt(4921000L);
// [END fs_end_at_field_query_cursor]
return query;
}
Aggregations