Search in sources :

Example 11 with WriteResult

use of com.google.cloud.firestore.WriteResult in project spring-cloud-gcp by spring-cloud.

the class FirestoreSampleApp method writeDocumentFromObject.

private void writeDocumentFromObject() throws ExecutionException, InterruptedException {
    // Add document data with id "joe" using a custom User class
    User data = new User("Joe", Arrays.asList(new Phone(12345, PhoneType.CELL), new Phone(54321, PhoneType.WORK)));
    // .get() blocks on response
    WriteResult writeResult = this.firestore.document("users/joe").set(data).get();
    System.out.println("Update time: " + writeResult.getUpdateTime());
}
Also used : WriteResult(com.google.cloud.firestore.WriteResult)

Example 12 with WriteResult

use of com.google.cloud.firestore.WriteResult in project spring-cloud-gcp by spring-cloud.

the class FirestoreSampleApp method writeDocumentFromMap.

private void writeDocumentFromMap() throws InterruptedException, java.util.concurrent.ExecutionException {
    DocumentReference docRef = this.firestore.collection("users").document("ada");
    // Add document data with id "ada" using a hashmap
    Map<String, Object> data = new HashMap<>();
    data.put("name", "Ada");
    data.put("phones", Arrays.asList(123, 456));
    // asynchronously write data
    ApiFuture<WriteResult> result = docRef.set(data);
    // result.get() blocks on response
    System.out.println("Update time: " + result.get().getUpdateTime());
}
Also used : WriteResult(com.google.cloud.firestore.WriteResult) HashMap(java.util.HashMap) DocumentReference(com.google.cloud.firestore.DocumentReference)

Example 13 with WriteResult

use of com.google.cloud.firestore.WriteResult in project spring-cloud-gcp by spring-cloud.

the class FirestoreExample method writeDocumentFromObject2.

void writeDocumentFromObject2() throws ExecutionException, InterruptedException {
    // Add document data with id "joe" using a custom User class
    User data = new User("Joseph", Arrays.asList(new Phone(23456, PhoneType.CELL), new Phone(65432, PhoneType.WORK)));
    // .get() blocks on response
    WriteResult writeResult = this.firestore.document("users/joe").set(data).get();
    LOGGER.info("Update time: " + writeResult.getUpdateTime());
}
Also used : WriteResult(com.google.cloud.firestore.WriteResult)

Aggregations

WriteResult (com.google.cloud.firestore.WriteResult)13 DocumentReference (com.google.cloud.firestore.DocumentReference)8 City (com.example.firestore.snippets.model.City)6 HashMap (java.util.HashMap)5 PubSubMessage (com.getstarted.background.objects.PubSubMessage)1 TranslateMessage (com.getstarted.background.objects.TranslateMessage)1 CollectionReference (com.google.cloud.firestore.CollectionReference)1 Firestore (com.google.cloud.firestore.Firestore)1 WriteBatch (com.google.cloud.firestore.WriteBatch)1 Translate (com.google.cloud.translate.Translate)1 Translation (com.google.cloud.translate.Translation)1 ImmutableList (com.google.common.collect.ImmutableList)1 ProtoChange (com.google.startupos.common.firestore.ProtoChange)1 ProtoQuerySnapshot (com.google.startupos.common.firestore.ProtoQuerySnapshot)1 CiRequest (com.google.startupos.tools.reviewer.ReviewerProtos.CiRequest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 ServletException (javax.servlet.ServletException)1