Search in sources :

Example 26 with CollectionReference

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

the class QueryDataSnippets method createCompositeIndexChainedQuery.

/**
 * An instance of a currently unsupported chained query: equality with inequality.
 * NOTE : Requires support for creation of composite indices.
 *
 * @return query
 */
Query createCompositeIndexChainedQuery() {
    CollectionReference cities = db.collection("cities");
    // [START fs_composite_index_chained_query]
    Query chainedQuery2 = cities.whereEqualTo("state", "CA").whereLessThan("population", 1000000L);
    // [END fs_composite_index_chained_query]
    return chainedQuery2;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 27 with CollectionReference

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

the class QueryDataSnippets method createChainedQuery.

/**
 * Creates chained where clauses.
 *
 * <p>Note : equality and inequality clauses over multiple fields cannot be chained.
 *
 * @return query
 */
Query createChainedQuery() {
    CollectionReference cities = db.collection("cities");
    // [START fs_chained_query]
    Query chainedQuery1 = cities.whereEqualTo("state", "CO").whereEqualTo("name", "Denver");
    // [END fs_chained_query]
    return chainedQuery1;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 28 with CollectionReference

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

the class QueryDataSnippets method createStartAtFieldQueryCursor.

/**
 * Create a query defining the start point of a query.
 *
 * @return query
 */
Query createStartAtFieldQueryCursor() {
    CollectionReference cities = db.collection("cities");
    // [START fs_start_at_field_query_cursor]
    Query query = cities.orderBy("population").startAt(4921000L);
    // [END fs_start_at_field_query_cursor]
    return query;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 29 with CollectionReference

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

the class QueryDataSnippets method createWhereWithOrderByAndLimitQuery.

/**
 * Creates a query that combines where clause with order by and limit operator.
 *
 * @return query
 */
Query createWhereWithOrderByAndLimitQuery() {
    CollectionReference cities = db.collection("cities");
    // [START fs_where_order_by_limit_query]
    Query query = cities.whereGreaterThan("population", 2500000L).orderBy("population").limit(2);
    // [END fs_where_order_by_limit_query]
    return query;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 30 with CollectionReference

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

the class QueryDataSnippets method prepareExamples.

/**
 * Creates cities collection and add sample documents to test queries.
 *
 * @return collection reference
 */
void prepareExamples() throws Exception {
    // [START fs_query_create_examples]
    CollectionReference cities = db.collection("cities");
    List<ApiFuture<WriteResult>> futures = new ArrayList<>();
    futures.add(cities.document("SF").set(new City("San Francisco", "CA", "USA", false, 860000L)));
    futures.add(cities.document("LA").set(new City("Los Angeles", "CA", "USA", false, 3900000L)));
    futures.add(cities.document("DC").set(new City("Washington D.C.", null, "USA", true, 680000L)));
    futures.add(cities.document("TOK").set(new City("Tokyo", null, "Japan", true, 9000000L)));
    futures.add(cities.document("BJ").set(new City("Beijing", null, "China", true, 21500000L)));
    // (optional) block on documents successfully added
    ApiFutures.allAsList(futures).get();
// [END fs_query_create_examples]
}
Also used : ApiFuture(com.google.api.core.ApiFuture) ArrayList(java.util.ArrayList) City(com.example.firestore.snippets.model.City) 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