title: how to save and read map in mongoDB using java
body: <p>i have a collection in mongo that contains 3 column as below:</p>
  
  <pre><code>{ 
  "_id" : { "$oid" : "5396ad5de4b09ea27a641ed6"} , 
  "word" : "test_word" , 
  "doc_occurrence" : "'total':25,'sport':10" ,
   "total_occurrence" : "'total':32,'sport':15"
  }
  </code></pre>
  
  <p>doc_occurrence and total_occurrence are Map. i insert documents to collection this way:</p>
  
  <pre><code>        private boolean add(String word, Map&lt;String, Integer&gt; docOccurrence, Map&lt;String, Integer&gt; totalOccurrence) {
      BasicDBObject document = new BasicDBObject();
      document.put("word", word);
      document.put("docOccurrence", docOccurrence);
      document.put("totalOccurrence", totalOccurrence);
      try {
          synchronized (LOCK_WRITE) {
              table.insert(WriteConcern.SAFE,document);
  
  
          }
      } catch (MongoException e) {
          logger.error("Could not insert new row to word_cat : {}", e.getMessage());
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>i want to read maps from DB this way:</p>
  
  <pre><code>        BasicDBObject searchQuery = new BasicDBObject();
          searchQuery.put("word",word);
      try {
          DBCursor cursor = table.find(searchQuery);
          if (cursor.hasNext()) {
              DBObject doc = cursor.next();
              Map&lt;String, Integer&gt; map = (Map&lt;String, Integer&gt;)doc.get("docOccurrence"); // ClassCastException
  </code></pre>
  
  <p>but i get</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
  </code></pre>
  
  <p>is there any way i cat read maps directly from DB? if not, what is altenative?</p>
  
  <p>p.s: BSON convert map to String. in fact BSON keys must be String!</p>