title: Subscribing twice on Spring Data MongoDB save() results in double insert
body: <p>We encountered the following behaviour which we do understand, however we'd like to find out whether it is expected and whether it might be of interest to document it as some kind of pitfall.</p>
  
  <p>We're experimenting with Spring Boot 2/Spring WebFlux and set up a small application that basically has something like this (all shortened):</p>
  
  <pre class="lang-java prettyprint-override"><code>@PostMapping
  public Mono&lt;Todo&gt; addTodos( @RequestBody Person person ) {
      return personService.addPerson( person );
  }
  </code></pre>
  
  <p>The service first looked like this, as we want to publish the event of a person addition also to a message queue:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class PersonService {
      public Mono&lt;Person&gt; addPerson( Person person ) {
          Mono&lt;Person&gt; addedPerson = personRepository.save( person );
          addedPerson.subscribe( p -&gt; rabbitTemplate.convertAndSend( "persons", p ) );
          return addedPerson;
      }
  }
  </code></pre>
  
  <p>So, this is obviously wrong to do it like that. The <code>.subscribe()</code> triggers the flow and we assume that the reactive REST controller does the same in the background before serializing the data for the response, resulting in a second parallel flow. In the end we ended up with two duplicate entries in the <code>persons</code> collection in the database.</p>
  
  <p>After this lengthy introduction finally the question: is this expected behaviour that multiple subscribers trigger multiple inserts (basically, if you subscribe <code>n</code> times you get <code>n</code> inserts)?</p>
  
  <p>If yes this might be a pitfall to emphasize for beginners, especially if our understanding is correct, that the reactive REST controllers perform a <code>.subscribe()</code> under the hoods.</p>