title: mongodb c# how to work with BSON document
body: <p>I've spent MANY hours looking for the answer... 
  This is very easy in PHP but I just can't put it together in C#(I'm new to C# and mongo...)
  I'm trying to iterate through all levels of a stored document. The document looks like this:</p>
  
  <pre><code>{
      "_id": ObjectId("51f90101853bd88971ecdf27"),
      "fields": [
          {
              "ID": ObjectId("51fd09498b080ee40c00514e"),
              "NAME": "ID",
              "TYPE": "Text"
          },
          {
              "ID": ObjectId("51fd09a68b080ee40c0064db"),
              "NAME": "Title",
              "TYPE": "Text"
          },
          {
              "ID": ObjectId("51fd09b28b080ee40c004d31"),
              "NAME": "Start Date",
              "TYPE": "Date"
          },
          {
              "ID": ObjectId("51fd09c28b080ee40c007f2e"),
              "NAME": "Long Description",
              "TYPE": "Memo"
          }
      ],
      "name": "TODB",
      "updated": "Wed Jul 31 2013 08:20:17 GMT-0400 (Eastern Daylight Time)"
  }
  </code></pre>
  
  <p>I have no problem accessing the "name" and "updated" but can't figure out how to access the "fields" array.</p>
  
  <p>Code so far :</p>
  
  <pre><code>{
      MongoServer mongo = MongoServer.Create();
      mongo.Connect();
      var db = mongo.GetDatabase("forms"); 
      mongo.RequestStart(db);
      var collection = db.GetCollection("forms");
      var query = new QueryDocument("name",
      "TODB"); 
      mongo.Disconnect();
  }
  
  @foreach(BsonDocument item in collection.Find(query))
  {
      @item.GetElement("name").Value
      @item.GetElement("_id").Value
  }
  </code></pre>
  
  <p>Again, I am able to access the name and _id just not any of the sub document values.</p>
  
  <p>Thanks in advance for any assistance!
  After I get the reading figured out, I am also going to want to write data....</p>