use of com.google.cloud.firestore.Query 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;
}
use of com.google.cloud.firestore.Query 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;
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippetsIT method testMultipleCursorConditions.
@Test
public void testMultipleCursorConditions() throws Exception {
// populate us_cities collection
Map<String, String> city1 = new ImmutableMap.Builder<String, String>().put("name", "Springfield").put("state", "Massachusetts").build();
Map<String, String> city2 = new ImmutableMap.Builder<String, String>().put("name", "Springfield").put("state", "Missouri").build();
Map<String, String> city3 = new ImmutableMap.Builder<String, String>().put("name", "Springfield").put("state", "Wisconsin").build();
db.collection("us_cities").document("Massachusetts").set(city1).get();
db.collection("us_cities").document("Missouri").set(city2).get();
db.collection("us_cities").document("Wisconsin").set(city3).get();
Query query1 = db.collection("us_cities").orderBy("name").orderBy("state").startAt("Springfield");
// all documents are retrieved
QuerySnapshot querySnapshot = query1.get().get();
List<QueryDocumentSnapshot> docs = querySnapshot.getDocuments();
assertEquals(3, docs.size());
// Will return "Springfield, Missouri" and "Springfield, Wisconsin"
Query query2 = db.collection("us_cities").orderBy("name").orderBy("state").startAt("Springfield", "Missouri");
// only Missouri and Wisconsin are retrieved
List<String> expectedResults = Arrays.asList("Missouri", "Wisconsin");
List<String> result = getResults(query2);
assertTrue(Objects.equals(result, expectedResults));
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippetsIT method testRangeQuery.
@Test
public void testRangeQuery() throws Exception {
Query q = queryDataSnippets.createRangeQuery();
Set<String> result = getResultsAsSet(q);
Set<String> expectedResults = new HashSet<>(Arrays.asList("SF", "LA"));
assertTrue(Objects.equals(result, expectedResults));
}
use of com.google.cloud.firestore.Query in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippetsIT method testRangeWithOrderByQuery.
@Test
public void testRangeWithOrderByQuery() throws Exception {
Query q = queryDataSnippets.createRangeWithOrderByQuery();
List<String> result = getResults(q);
List<String> expectedResults = Arrays.asList("LA", "TOK", "BJ");
assertEquals(result, expectedResults);
}
Aggregations