title: MongoDb c# update array in document
body: <p>I have the following code:</p>
  
  <pre><code>_eventInstanceRepository.GetInnerCollection().Update(
                                Query.EQ("_id", listingEventModel.Id),
                                Update.PushWrapped&lt;string[]&gt;("ArtistIds", ids.ToArray()));
  </code></pre>
  
  <p>Which is designed to update the following document:</p>
  
  <pre><code>public class ListingEvent
  {       
      public ObjectId Id { get; set; }
      public string[] ArtistIds { get; set; }        
  }
  </code></pre>
  
  <p>ids is a List</p>
  
  <p>Any ideas why this isn't updating the docs?</p>
  
  <p>[UPDATE]</p>
  
  <p>Also tried this!</p>
  
  <pre><code>foreach (var id in ids)
  {
      _eventInstanceRepository.GetInnerCollection().Update(
                                Query.EQ("_id", listingEventModel.Id),
                                Update.Push("ArtistIds", id));
  }
  </code></pre>
  
  <p>No luck...</p>
  
  <p>[UPDATE]</p>
  
  <p>Going back to RavenDb - at least for now. I don't see how MongoDb is a viable option the whole time there are no real sources discussing (slightly more complex than flat structure) document updates on the internet and the examples I can find simply do not work.</p>
  
  <p>[UPDATE]</p>
  
  <p>Here is the repository code:</p>
  
  <pre><code>public class Repository&lt;T&gt; : IRepository&lt;T&gt;
  {
      private readonly MongoCollection&lt;T&gt; _docs;
  
      public Repository(MongoCollection&lt;T&gt; docs)
      {
          _docs = docs;
      }
  
      public IList&lt;T&gt; GetAll()
      {
          return _docs.FindAll().Select&lt;T, T&gt;(x =&gt; x.As&lt;T&gt;()).ToList();
      }
  
      //HACK!
      public MongoCollection&lt;T&gt; GetInnerCollection(){
          return _docs;
      }
  
      public void Save(T doc)
      {
          _docs.Save(doc);
      }
  
      public void Save(IEnumerable&lt;T&gt; docsToSave)
      {
          foreach (var doc in docsToSave) Save(doc);
      }
  
      public void Dispose()
      {
          throw new NotImplementedException();
      }
  
      public void Delete(string id)
      {
          var query = Query.EQ("_id", id);
          _docs.Remove(query);
      }
  }
  </code></pre>