title: How to insert multiple documents at once in MongoDB through Java
body: <p>I am using MongoDB in my application and  was needed to insert multiple documents inside a MongoDB collection .
  The version I am using is of 1.6 </p>
  
  <p>I saw an example here </p>
  
  <p><a href="http://docs.mongodb.org/manual/core/create/">http://docs.mongodb.org/manual/core/create/</a></p>
  
  <p>in the </p>
  
  <p><strong>Bulk Insert Multiple Documents</strong>  Section </p>
  
  <p>Where the author was passing an array to do this .</p>
  
  <p>When I tried the same , but why it isn't allowing , and please tell me how can I insert multiple documents at once ??</p>
  
  <pre><code>package com;
  
  import java.util.Date;
  
  import com.mongodb.BasicDBObject;
  import com.mongodb.DB;
  import com.mongodb.DBCollection;
  import com.mongodb.MongoClient;
  
  public class App {
  
      public static void main(String[] args) {
          try {
              MongoClient mongo = new MongoClient("localhost", 27017);
              DB db = mongo.getDB("at");
              DBCollection collection = db.getCollection("people");
  
              /*
               * BasicDBObject document = new BasicDBObject();
               * document.put("name", "mkyong"); document.put("age", 30);
               * document.put("createdDate", new Date()); table.insert(document);
               */
  
              String[] myStringArray = new String[] { "a", "b", "c" };
  
              collection.insert(myStringArray); // Compilation error at this line saying that "The method insert(DBObject...) in the type DBCollection is not applicable for the arguments (String[])"
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  
  <p>Please let me know what is the way so that I can insert multiple documents at once through java .</p>