use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.
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]
// [START firestore_query_filter_compound_multi_eq_lt]
Query chainedQuery2 = cities.whereEqualTo("state", "CA").whereLessThan("population", 1000000L);
// [END fs_composite_index_chained_query]
return chainedQuery2;
}
use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.
the class QueryDataSnippets method notEqualsQuery.
Query notEqualsQuery() {
// [START fs_query_not_equals]
// [START firestore_query_filter_not_eq]
CollectionReference citiesRef = db.collection("cities");
Query query = citiesRef.whereNotEqualTo("capital", false);
// [END fs_query_not_equals]
return query;
}
use of com.google.cloud.firestore.CollectionReference in project java-firestore by googleapis.
the class NativeImageFirestoreSample method createUserDocumentPojo.
static void createUserDocumentPojo(Firestore db) throws Exception {
CollectionReference collectionReference = db.collection(USERS_COLLECTION);
WriteResult result = collectionReference.document().set(new Person("Alan", "Turing", 1912)).get();
System.out.println("Created user by POJO. Timestamp: " + result.getUpdateTime());
}
use of com.google.cloud.firestore.CollectionReference in project quarkus-google-cloud-services by quarkiverse.
the class FirestoreResource method firestore.
@GET
@Produces(MediaType.TEXT_PLAIN)
public String firestore() throws ExecutionException, InterruptedException {
// insert 3 persons
CollectionReference persons = firestore.collection("persons");
List<ApiFuture<WriteResult>> futures = new ArrayList<>();
futures.add(persons.document("1").set(new Person(1L, "John", "Doe")));
futures.add(persons.document("2").set(new Person(2L, "Jane", "Doe")));
futures.add(persons.document("3").set(new Person(3L, "Charles", "Baudelaire")));
ApiFutures.allAsList(futures).get();
// search for lastname=Doe
Query query = persons.whereEqualTo("lastname", "Doe");
ApiFuture<QuerySnapshot> querySnapshot = query.get();
return querySnapshot.get().getDocuments().stream().map(document -> document.getId() + " - " + document.getString("firstname") + " " + document.getString("lastname") + "\n").collect(Collectors.joining());
}
use of com.google.cloud.firestore.CollectionReference in project java-docs-samples by GoogleCloudPlatform.
the class QueryDataSnippets method createAQuery.
/**
* Creates a sample query.
*
* @return query
*/
Query createAQuery() throws Exception {
// [START fs_create_query]
// 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;
}
Aggregations