title: Replace in MongoDB With C#
body: <p>I am trying to actually replace a collection of Objects of type Game in my Collection "Games".</p>
  
  <p>I want to replace these Objects with entirely new Objects. I have researched a bit on MongoDB and I see that 'UpdateMany' will replace Fields with new values but that's not exactly what I want. I wish to replace the entire Object.</p>
  
  <p>For reference, this is my Game class:</p>
  
  <pre><code>public class Game
  {
    public Guid Id { get; set; }
    public string Title { get; set; }
    public string Developer { get; set; }
    public int ProjectId { get; set; }
  
    public Game()
    {
     this.Id = Guid.NewGuid();
   }
  }
  </code></pre>
  
  <p>This is my method I am using to attempt a bulk Replace. I am passing in a ProjectId, so for all of the Game Objects that have a ProjectId = to the argument, replace the Object with a new Game Object.</p>
  
  <pre><code> public static void ReplaceGame(int ProjectId, IMongoDatabase Database)
   {
     IMongoCollection&lt;Game&gt; gameCollection = Database.GetCollection&lt;Game&gt;("Game");
     List&lt;Game&gt; gameCollectionBeforeReplacement = gameCollection.Find(g =&gt; true).ToList();
     if (gameCollectionBeforeReplacement.Count == 0)
     {
       Console.WriteLine("No Games in Collection...");
       return;
      }
  
      var filter = Builders&lt;Game&gt;.Filter.Eq(g =&gt; g.ProjectId, ProjectId);
      foreach (Game game in gameCollection.AsQueryable())
          gameCollection.ReplaceOneASync(filter, new Game() { Title = "REPLACEMENT TITLE" });
      }
  </code></pre>
  
  <p>Not only does this take an excessive amount of time. I suspect it's because of the .AsQueryable() call but it also doesn't work. I am wondering how I can actually replace all instances picked up by my filter with new Game Objects.</p>