title: Insert JSON into an existing MongoDB collection
body: <p>I understood my mistake :) Thanks guys.
  I have one more Question, suppose i have multiple documents with the below structure in "Customer" collection.</p>
  
  <pre><code>{
      "customerId":100,
      "FirstName":"xyz",
      "lastname":"pqr",
      "address":[
         {
            "house":44,
            "city":"Delhi",
            "country":"india"
         }
      ],
      "employer":[
         {
            "cmpName":"ABC",
            "type":"IT"
         }
      ]
  </code></pre>
  
  <h2>     }</h2>
  
  <p>Now i have a JSON file as below:</p>
  
  <pre><code>{
      "customerId":100,
      "address":[
         {
            "house":99,
            "city":"MUMBAI",
            "country":"INDIA"
         }
      ]
   }
  </code></pre>
  
  <p>Can you please tell me how can i update the address array for customerId = 100 using the above JSON file in my c# code.</p>
  
  <p>Please suggest.!</p>
  
  <p>Thanks in advance :)</p>
  
  <hr>
  
  <p>I am writing a C# (C sharp)(.Net) code to insert a JSON file in mongoDB. i have a jsonfile " records.JSON " which has multiple document in one single row in it,   like :</p>
  
  <pre><code>[{"customerId" : 100,"FirstName" : "xyz","lastname" : "pqr","address":[{"house": 44,"city" : "Delhi", "country" : "india"}],"employer":[{"cmpName" : "ABC","type" : "IT"}]}][{"customerId" : 101,"FirstName" : "LMN","lastname" : "GHI","address":[{"house": 90,"city" : "NewYork", "country" : "US"}],"employer":[{"cmpName" : "ABC","type" : "IT"}]}]
  </code></pre>
  
  <p>I need to insert this JSON file into an existing MongoDB collection.
  So far I have the following code to connect and insert to mongodb :</p>
  
  <pre><code>public static void Main (string[] args)
          {
              var connectionString = "mongodb://localhost";    
              var client = new MongoClient(connectionString);
              var server = client.GetServer();
              server.Connect();
              var database = server.GetDatabase("test");
   var collection = database.GetCollection&lt;BsonDocument&gt;("test_collection");
              string text = System.IO.File.ReadAllText(@"records.JSON");
              var bsonDoc = BsonArray.Parse (text);
              collection.Insert (bsonDoc);
          }
  </code></pre>
  
  <p>But this is giving me error as : " an array cannot be written to root level of BSON document" 
  And if i parse BSON as : <code>var bsonDoc = BsonDocument.Parse (text);</code>
  it gives me error as : <code>Cannot deserialize BsonDocumet from BsonType Array.</code></p>
  
  <p>Can anybody Please help me to understand How do i insert the JSON file into the mongoDB Collection. ??</p>
  
  <p>Any help is appreciated.. Thanks in advance.</p>