title: Correct pattern to insert or update existed entity with spring data reactive
body: <p>I implement an application with spring data (mongo).</p>
  
  <ul>
  <li>It gets data from external service</li>
  <li>Store it to DB</li>
  <li>If item does not exist I'd like to insert it to db</li>
  <li>If item exists but has same md5 hash with external item - do nothing</li>
  <li>If item exists in DB and md5 hashes are not equal I'd like to update it</li>
  </ul>
  
  <p>I have the code</p>
  
  <pre><code>public Mono&lt;Void&gt; processItems() {  
    return externalService.getItems() //this returns Flux&lt;Item&gt;
           .flatMap(this::createOrUpdateItem)
           .flatMap(itemRepository::save)
           .then() 
  }
  
  private Mono&lt;Item&gt; createOrUpdateItem(Item item) {  
    return itemRepository.findById(item.getId) //this returns Mono&lt;Item&gt;
            .flatMap(itemFromDb -&gt; updateItem(itemFromDb, item))
            .defaultIfEmpty(item) 
  }
  
  private Mono&lt;Item&gt; updateItem(Item itemFromDb, Item item){
    if(itemFromDb.getMd5.equals(item.getMd5)){
       return Mono.just(itemFromDb);
    }
  
    itemFromDb.setName(item.getName)
              .setDescription(item.getDescription); 
  
    return Mono.just(itemFromDb);
  }
  </code></pre>
  
  <p>How does it work:</p>
  
  <ul>
  <li>If item does not exist it stored in db</li>
  <li>If item exists and has same md5 hash updateItem returns existed in db and version in DB increases</li>
  <li>If item exists and md5 hashes are not equal updateItem set feilds and returns existed in db and version in DB increases</li>
  </ul>
  
  <p><strong>The problem is</strong>: when md5 hash are equal I don't want to cal DB. Because it increases version of the item in db but there were no changes.
  How to properly implement this algorithm?</p>
  
  <p>I can use @EqualsAndHashCode(exclude = "id") but not sure if it is a right way </p>