title: Java: How to insert a hashmap into MongoDB?
body: <p>I have a hashmap which I am trying to insert into MongoDB(version 3.6). I know about the method insertMany() -- which takes only List of Documents. I cannot create a list because I have duplicates in my data and I want to get rid of them. That's why I am creating a hashmap. Is there any way I can to insert the hashmap into Mongodb? I found one link <a href="https://www.mkyong.com/mongodb/java-mongodb-insert-a-document/" rel="nofollow noreferrer">https://www.mkyong.com/mongodb/java-mongodb-insert-a-document/</a> which shows how to insert the map into Mongodb</p>
  
  <pre><code>collection.insert(new BasicDBObject(documentMap));
  </code></pre>
  
  <p>But BasicDBObject is deprecated in the new mongoDB. My hashmap looks like this:</p>
  
  <pre><code>-1322771423 [ecn, KeywordMatch, http://insidedell.com/ecn, ECN]
  -2144339676 [product marketing, PhraseMatch, http://dellemc.com/product, Products]
  -214203024 [jive, ExactMatch, http://test.com/jive, Jive test]
  -493382214 [search, ExactMatch, http://example.com, Search Consultancy]
  </code></pre>
  
  <p>Basically I want my MongoDB collecion to look like this:</p>
  
  <pre><code>new_collection
  {
  _id: -493382214
  query: ExactMatch,
  link: http://example.com,
  content: Search Consultancy
  }
  {
  _id:
  ...
  }
  </code></pre>
  
  <p>Edit: <strong>Background on my problem</strong>: I am trying to insert a CSV file into MongoDB. My CSV file has duplicates row(identical row). That's why I have to convert them into a hashmap instead of storing them in an arrayList(Document). I know we can insert into Mongodb by using insertMany(List(Document)), but I need to avoid those duplicates.</p>
  
  <p>Any help is appreciated.</p>