title: How to store prices in MongoDB for best practices?
body: <p>First thanks in advance for the help.</p>
  
  <p>I have an application with Spring Boot and mongo using Spring Data and I have something like this:</p>
  
  <pre><code>@Document("products")
  class Product {
      @Id
      private String $id;
      private String $name;
      private Money price;
      private Money deliveryPrice;
  }
  
  class Money {
      private BigDecimal amount;
      private Currency currency;
  }
  </code></pre>
  
  <p>If I save a product it saves like:</p>
  
  <pre><code>{
      _id: ObjectId("AAAA"),
      name: "Product 1",
      price: {
          amount: "100",
          currency: "EUR"
      },
      deliveryPrice: {
          amount: "10",
          currency: "EUR"
      }
  }
  </code></pre>
  
  <p>It's correct but I don't like how it saves.</p>
  
  <p>I would like to store like:</p>
  
  <pre><code>{
      _id: ObjectId("AAAA"),
      name: "Product 1",
      price: DecimalNumber(100),
      deliveryPrice: DecimalNumber(10),
      currency: "EUR"
  }
  </code></pre>
  
  <p>That way I am not duplicating information that is not needed in all the prices value.</p>
  
  <p>How can I solve this?
  Is this the best solution? In case not how should it be?</p>
  
  <p>Thanks</p>