title: MongoDB C# Driver FindAndModify
body: <p>I'm trying to run a FindAndModify operation in MongoDB, but I'm getting an unusual exception</p>
  
  <pre><code>var query = Query.EQ("_id", wiki.ID);
  var sortBy = SortBy.Descending("Version");
  var update = Update.Set("Content", wiki.Content)
                      .Set("CreatedBy", wiki.CreatedBy)
                      .Set("CreatedDate", wiki.CreatedDate)
                      .Set("Name", wiki.Name)
                      .Set("PreviousVersion", wiki.PreviousVersion.ToBsonDocument())
                      .Set("Title", wiki.Title)
                      .Set("Version", wiki.Version);
  var result = collection.FindAndModify(query, sortBy, update, true);
  </code></pre>
  
  <p>The exception I get is </p>
  
  <pre><code>WriteStartArray can only be called when State is Value, not when State is Initial
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  
  Exception Details: System.InvalidOperationException: WriteStartArray can only be called when State is Value, not when State is Initial
  
  Source Error:
  
  Line 45:                 var query = Query.EQ("_id", wiki.ID);
  Line 46:                 var sortBy = SortBy.Descending("Version");
  Line 47:                 var update = Update.Set("Content", wiki.Content)
  Line 48:                                    .Set("CreatedBy", wiki.CreatedBy)
  Line 49:                                    .Set("CreatedDate", wiki.CreatedDate)
  </code></pre>
  
  <p>Thoughts? I've implemented this per the API on mongodb's site.</p>
  
  <p>EDIT--
  Fixed per @jeffsaracco</p>
  
  <pre><code>var update = Update.Set("Content", wiki.Content)
  .Set("CreatedBy", wiki.CreatedBy)
  .Set("CreatedDate", wiki.CreatedDate)
  .Set("Name", wiki.Name)
  .PushAllWrapped&lt;WikiHistory&gt;("PreviousVersion", wiki.PreviousVersion)
  .Set("Title", wiki.Title)
  .Set("Version", wiki.Version);
  </code></pre>