1

I am using spring-cloud-gcp-starter-data-firestore for accessing Google Cloud Firestore in my Java Spring application.

Currently, my entity looks like this:

public class Subscription {

    public String userId;
    public String companyId;

    // other properties

}

However, I obtain the userId and companyId via a reactor.core.publisher.Mono in org.springframework.security.core.context.ReactiveSecurityContextHolder.

How can I persist both properties which are nested inside Monos without resorting to Mono#block?

Harold L. Brown
  • 8,423
  • 11
  • 57
  • 109
  • What do you mean by `persist both properties`? Why do you want to avoid `Mono#block`? – Juancki Jan 29 '20 at 11:10
  • @Juancki By using `Mono#block` I would throw "away all the benefits of the Reactive Streams" according to the Spring documentation: https://spring.io/blog/2016/06/13/notes-on-reactive-programming-part-ii-writing-some-code – Harold L. Brown Jan 29 '20 at 12:43

2 Answers2

0

I am now using Mono#zipWith to combine both Monos. Then I am creating the entity inside Mono#flatMap.

service.getCompanyId()
   .zipWith(service.getUserId())
   .flatMap(objects -> createEntity(objects.getT1(), objects.getT2()))
Harold L. Brown
  • 8,423
  • 11
  • 57
  • 109
0

I suggest following the tutorial in the Google codelab.

Here you can find that Firestore can be in Datastore mode which makes the previous tutorial suitable for you.

Juancki
  • 1,793
  • 1
  • 14
  • 21