title: Store HashMap on MongoDB
body: <p>I need to refactor the MongoDB object I'm saving but it's not clear for me how to save the data to give me the possibility to query the MongoDB later in the right way. </p>
  
  <p>This is a prototype of the class I'm using on my Java code:</p>
  
  <pre><code>public class UserProfile {
  
      /** UUID : for MONGO Authentication / Shiro / MongoDB persistence database */
      private String UUID;
  
      /** Activation state of the user */
      private Integer status;
  
      private boolean admin;
  
      /**
       * All security properties like : password temporaryPassword; active; token;
       */
      private HashMap&lt;String, Object&gt; securityProperties = new HashMap&lt;String, Object&gt;();
  
      /**
       * Data structure to store information related to user like Doctory,
       * Birthday, Region, Sex, etc. Driven by interface: at this level isn't
       * important what's the content of this object
       */
      private Map&lt;String, String&gt; user_details;
  
      /** Score confidence level: 0 default */
      private int score_confidence_level;
  
      /**
       * UserModels : list of models / scores; key is model_id and bean contains
       * all information about that model
       */
      private LinkedHashMap&lt;Integer, Model&gt; userModels;
  </code></pre>
  
  <p>This is a subset of the object I'm saving now in mongo:</p>
  
  <pre><code>{
      "_id" : "f9f44e87-4260-4699-99a6-af6b58b4fb7e",
      "address" : {},
      "lastUpdate" : "1414083484838",
      "listvalues" : {},
      "mapvalues" : {
          "SECURITY" : {
              "CONFIRMATIONTOKEN" : null,
              "TEMPORARYPASSWORD" : "0",
              "PASSWORD" : "$shiro1$SHA-256$500000$JXOo84Wapg0Tt50UIuwqRg==$bSBShfqpXmdMwMuE3IWknbmZeyXGFhAWSFyjAsYU5+4="
          },
          "MY_PROFILE" : {}
      },
      "userModels" : {
          "5067" : {              
              "generated_date_timestamp" : NumberLong(1413985161866),
              "model_id" : 5067,
              "score_id" : {
                  "0" : {
                      "score_level_id" : 5267,
                      "confidence" : 0,
                      "generated_timestamp" : NumberLong(1413985161866)
                  }
              },
              "points" : 0,
              "delta_points" : 0,
              "override_model" : 0,
              "override_score" : 0,
              "model_lifecycle" : {
                  "model_status" : 0
              },
              "model_type" : 0,
              "questionnaire" : {}
          },
          "5079" : {          
              "generated_date_timestamp" : NumberLong(1413985161866),
              "model_id" : 5079,
              "score_id" : {
                  "0" : {
                      "score_level_id" : 5292,
                      "confidence" : 0,
                      "generated_timestamp" : NumberLong(1413985161866)
                  }
              },
              "points" : 0,
              "delta_points" : 0,
              "override_model" : 0,
              "override_score" : 0,
              "model_lifecycle" : {
                  "model_status" : 0
              },
              "model_type" : 0,
              "questionnaire" : {}
          },
  </code></pre>
  
  <p>The problem here is with <code>userModels</code>: saved in this way doesn't allow me to execute some query different than:</p>
  
  <pre><code>db.collection.find({"userModelHistory.8401.model_id" : "8401"});
  </code></pre>
  
  <p>To generate the report required, I need to search directly values in the fields like <code>delta_points</code>.</p>
  
  <p>So, my point is, how to save HashMap in MongoDB? </p>
  
  <p>Another question, the UUID, it's not saved as a mongo _id (which contains the creation date). How can I generate it in the right way?</p>
  
  <p>thanks,<br />
  Andrea</p>