title: Creating a nested document in mongoDB using spring
body: <p><strong>What I get</strong></p>
  
  <p>This is what I get saved in mongoDB, in the Dialog Collection</p>
  
  <pre><code>"_id": "5a61c7c7d5981a4b88b5fe17",
  "_class": "com.kalsym.next.gen.campaign.data.Dialog",
  "message": {
      "title": "Welcome Message",
      "subTitle": "Click SUbscribe to avail the offer",
      "url": "www.hotmail.com"
  },
  "options": [{
      "IR": "Thanks for subscription",
      "value": "sub",
      "path": "sub"
  },
  {
      "IR": "www.kalsym.com/NoThanks",
      "value": "NoThnks",
      "path": "NT"
  }]
  </code></pre>
  
  <p><strong>What I want:</strong></p>
  
  <pre><code>"_id": "5a4e16547d4cea1604bf28f8",
  "message": {
      "Title": "",
      "SubTitle": "Do you want to talk to CSR?",
      "URL": ""
  },
  "options": {
      "Yes": {
          "IR": "You will get a callback within 1 hour, thanks.",
          "value": "Yes",
          "path": "NT\\NotNow\\Yes"
      },
      "No": {
          "IR": "No Problem, have a good day!",
          "value": "No",
          "path": "NT\\NotNow\\No"
      }
  }
  </code></pre>
  
  <p>The issue is with the Options field. I want it to be a key value pair, not as a simple list.</p>
  
  <p>This is my Dialog class:</p>
  
  <pre><code>import java.util.List;
  import lombok.Getter;
  import lombok.Setter;
  import org.springframework.data.annotation.Id;
  import org.springframework.data.mongodb.core.mapping.Document;
  
  @Getter     
  @Setter
  @Document(collection = "Dialog")
  public class Dialog {
      @Id
      public String id;
      private Message message;
      private List&lt;Option&gt; options;
  
      public Dialog(final Message message, final List&lt;Option&gt; options) {
          this.message = message;
          this.options = options;
      }
  }
  </code></pre>
  
  <p>this is the Message class:</p>
  
  <pre><code>import lombok.Getter;
  import lombok.Setter;
  import lombok.ToString;
  
  @Getter
  @Setter
  @ToString
  public class Message {
  
      private String title;
      private String subTitle;
      private String url;
  
      public Message(final String title, final String subTitle, final String url) {
          this.title = title;
          this.subTitle = subTitle;
          this.url = url;
          }
  
  }
  </code></pre>
  
  <p>this is the option class:</p>
  
  <pre><code>import lombok.Getter;
  import lombok.Setter;
  import lombok.ToString;
  
  @Getter
  @Setter
  @ToString
  public class Option {
      private String IR;
      private String value;
      private String path;
  
      public Option(final String IR, final String value, final String path) {
          this.IR = IR;
          this.value = value;
          this.path = path;
      }
  }
  </code></pre>
  
  <p>Here is how I am saving it:</p>
  
  <pre><code>@SpringBootApplication
  @EnableMongoRepositories(basePackageClasses = DialogRepository.class)
  public class CampaignAPI implements CommandLineRunner {
  
      @Autowired
      private DialogRepository dialogRepository;
  
      public static void main(String[] args) {
          SpringApplication.run(CampaignAPI.class, args);
      }
  
      @Override
      public void run(String... strings) throws Exception {
  
          Message msg = new Message("Welcome Message", "Click SUbscribe to avail the offer", "www.hotmail.com");
          final Option subscribe = new Option("Thanks for subscription", "sub", "sub");
          final Option noThanks = new Option("www.kalsym.com/NoThanks", "NoThnks", "NT");
          List&lt;Option&gt; options = Arrays.asList(subscribe, noThanks);
  
          final Dialog welcomeDialog = new Dialog(msg, options);
          dialogRepository.save(welcomeDialog);
  
      }
  }
  </code></pre>
  
  <p><strong>My Question</strong></p>
  
  <ol>
  <li>Is there something wrong in how I am expecting it to be saved? i.e. Is the schema correct? (Wanting a to save key/value pair in options Object)</li>
  <li>Even if it is wrong, how do I save it exactly like the expected mongo document I have pasted above.</li>
  </ol>