Search in sources :

Example 66 with CollectionReference

use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.

the class QueryDataSnippets method createOrderByNameWithLimitToLastQuery.

/**
 * Creates a query that combines order by with limitToLast.
 *
 * @return query
 */
Query createOrderByNameWithLimitToLastQuery() {
    CollectionReference cities = db.collection("cities");
    // [START fs_order_by_name_limit_query]
    // [START firestore_query_order_limit]
    Query query = cities.orderBy("name").limitToLast(3);
    // [END fs_order_by_name_limit_query]
    return query;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 67 with CollectionReference

use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.

the class QueryDataSnippets method inQueryWithArray.

public Query inQueryWithArray() {
    // [START fs_query_filter_in_with_array]
    // [START firestore_query_filter_in_with_array]
    CollectionReference citiesRef = db.collection("cities");
    Query query = citiesRef.whereIn("regions", Arrays.asList(Arrays.asList("west_coast"), Arrays.asList("east_coast")));
    // [END fs_query_filter_in_with_array]
    return query;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 68 with CollectionReference

use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.

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]
    // [START firestore_query_order_desc_limit]
    Query query = cities.orderBy("name", Direction.DESCENDING).limit(3);
    // [END fs_order_by_name_desc_limit_query]
    return query;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 69 with CollectionReference

use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.

the class QueryDataSnippets method arrayContainsAnyQueries.

public Query arrayContainsAnyQueries() {
    // [START fs_query_filter_array_contains_any]
    // [START firestore_query_filter_array_contains_any]
    CollectionReference citiesRef = db.collection("cities");
    Query query = citiesRef.whereArrayContainsAny("regions", Arrays.asList("west_coast", "east_coast"));
    // [END fs_query_filter_array_contains_any]
    return query;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 70 with CollectionReference

use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.

the class RetrieveDataSnippets method prepareExamples.

/**
 * Create cities collection and add sample documents.
 */
void prepareExamples() throws Exception {
    // [START fs_retrieve_create_examples]
    // [START firestore_data_get_dataset]
    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, Arrays.asList("west_coast", "norcal"))));
    futures.add(cities.document("LA").set(new City("Los Angeles", "CA", "USA", false, 3900000L, Arrays.asList("west_coast", "socal"))));
    futures.add(cities.document("DC").set(new City("Washington D.C.", null, "USA", true, 680000L, Arrays.asList("east_coast"))));
    futures.add(cities.document("TOK").set(new City("Tokyo", null, "Japan", true, 9000000L, Arrays.asList("kanto", "honshu"))));
    futures.add(cities.document("BJ").set(new City("Beijing", null, "China", true, 21500000L, Arrays.asList("jingjinji", "hebei"))));
    // (optional) block on operation
    ApiFutures.allAsList(futures).get();
// [END firestore_data_get_dataset]
// [END fs_retrieve_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