Search in sources :

Example 21 with CollectionReference

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;
}
Also used : Query(com.google.cloud.firestore.Query) ArrayList(java.util.ArrayList) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 22 with CollectionReference

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;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 23 with CollectionReference

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;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 24 with CollectionReference

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;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 25 with CollectionReference

use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.

the class QueryDataSnippets method createInvalidRangeWithOrderByQuery.

/**
 * Creates an instance of an invalid range combined with order. Violates the constraint that range
 * and order by are required to be on the same field.
 *
 * @return query
 */
Query createInvalidRangeWithOrderByQuery() {
    CollectionReference cities = db.collection("cities");
    // Violates the constraint that range and order by are required to be on the same field
    // [START fs_invalid_range_order_by_query]
    Query query = cities.whereGreaterThan("population", 2500000L).orderBy("country");
    // [END fs_invalid_range_order_by_query]
    return query;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Aggregations

CollectionReference (com.google.cloud.firestore.CollectionReference)72 Query (com.google.cloud.firestore.Query)48 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)16 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)12 DocumentReference (com.google.cloud.firestore.DocumentReference)11 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)11 ArrayList (java.util.ArrayList)11 ExecutionException (java.util.concurrent.ExecutionException)9 Test (org.junit.Test)9 WriteResult (com.google.cloud.firestore.WriteResult)7 DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)6 ApiFuture (com.google.api.core.ApiFuture)6 BaseIntegrationTest (com.example.firestore.BaseIntegrationTest)5 HashMap (java.util.HashMap)5 FileSystemExecutionException (bio.terra.service.filedata.exception.FileSystemExecutionException)4 City (com.example.firestore.snippets.model.City)4 Firestore (com.google.cloud.firestore.Firestore)4 FileSystemCorruptException (bio.terra.service.filedata.exception.FileSystemCorruptException)2 TranslateMessage (com.getstarted.background.objects.TranslateMessage)2 FirestoreOptions (com.google.cloud.firestore.FirestoreOptions)2