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;
}
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;
}
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;
}
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;
}
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]
}
Aggregations