Search in sources :

Example 16 with CollectionReference

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;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 17 with CollectionReference

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;
}
Also used : Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 18 with CollectionReference

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());
}
Also used : WriteResult(com.google.cloud.firestore.WriteResult) CollectionReference(com.google.cloud.firestore.CollectionReference)

Example 19 with CollectionReference

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());
}
Also used : Firestore(com.google.cloud.firestore.Firestore) WriteResult(com.google.cloud.firestore.WriteResult) Produces(javax.ws.rs.Produces) ApiFutures(com.google.api.core.ApiFutures) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) CollectionReference(com.google.cloud.firestore.CollectionReference) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ApiFuture(com.google.api.core.ApiFuture) ExecutionException(java.util.concurrent.ExecutionException) Inject(javax.inject.Inject) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) Query(com.google.cloud.firestore.Query) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot) ApiFuture(com.google.api.core.ApiFuture) Query(com.google.cloud.firestore.Query) ArrayList(java.util.ArrayList) CollectionReference(com.google.cloud.firestore.CollectionReference) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 20 with CollectionReference

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;
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) Query(com.google.cloud.firestore.Query) CollectionReference(com.google.cloud.firestore.CollectionReference) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot)

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