Search in sources :

Example 6 with Query

use of com.google.cloud.firestore.Query 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 7 with Query

use of com.google.cloud.firestore.Query 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)

Example 8 with Query

use of com.google.cloud.firestore.Query 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 9 with Query

use of com.google.cloud.firestore.Query 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 10 with Query

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

the class QueryDataSnippets method createMultipleCursorConditionsQuery.

/* Create queries with multiple cursor conditions. */
void createMultipleCursorConditionsQuery() {
    // [START fs_multiple_cursor_conditions]
    // Will return all Springfields
    Query query1 = db.collection("cities").orderBy("name").orderBy("state").startAt("Springfield");
    // Will return "Springfield, Missouri" and "Springfield, Wisconsin"
    Query query2 = db.collection("cities").orderBy("name").orderBy("state").startAt("Springfield", "Missouri");
// [END fs_multiple_cursor_conditions]
}
Also used : Query(com.google.cloud.firestore.Query)

Aggregations

Query (com.google.cloud.firestore.Query)31 CollectionReference (com.google.cloud.firestore.CollectionReference)15 BaseIntegrationTest (com.example.firestore.BaseIntegrationTest)12 Test (org.junit.Test)12 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)6 HashSet (java.util.HashSet)3 Book (com.example.getstarted.objects.Book)2 Result (com.example.getstarted.objects.Result)2 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)2 ExecutionException (java.util.concurrent.ExecutionException)2 FirestoreException (com.google.cloud.firestore.FirestoreException)1 ListenerRegistration (com.google.cloud.firestore.ListenerRegistration)1 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1