Search in sources :

Example 56 with CollectionReference

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

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]
    // [START firestore_query_cursor_start_at_field_value_single]
    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 57 with CollectionReference

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

the class QueryDataSnippets method filterNotIn.

Query filterNotIn() {
    // [START fs_filter_not_in]
    // [START firestore_query_filter_not_in]
    CollectionReference citiesRef = db.collection("cities");
    Query query = citiesRef.whereNotIn("country", Arrays.asList("USA", "Japan"));
    // [END fs_filter_not_in]
    return query;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 58 with CollectionReference

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

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]
    // [START firestore_query_filter_single_examples]
    Query stateQuery = cities.whereEqualTo("state", "CA");
    Query populationQuery = cities.whereLessThan("population", 1000000L);
    Query nameQuery = cities.whereGreaterThanOrEqualTo("name", "San Francisco");
    // [END firestore_query_filter_single_examples]
    // [END fs_simple_queries]
    querys.add(stateQuery);
    querys.add(populationQuery);
    querys.add(nameQuery);
    return querys;
}
Also used : Query(com.google.cloud.firestore.Query) ArrayList(java.util.ArrayList) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 59 with CollectionReference

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

the class QueryDataSnippets method createQuery.

/**
 * Creates a sample query.
 *
 * @return query
 */
Query createQuery() throws Exception {
    // [START fs_create_query]
    // [START firestore_query_filter_eq_boolean]
    // 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;
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot)

Example 60 with CollectionReference

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

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]
    // [START firestore_query_order_limit_field_valid]
    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)

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