title: C# MongoDB driver save command creating duplicates
body: <p>I've just started working with MongoDB for c# and I'm trying to upsert some documents in a collection. I'm using the 'save' command (and even tried update with upsert flag on) but every time I run my code it keeps inserting duplicates: the new records have new object ids (randomly generated) but all the rest of the data is the same. What am I doing wrong? Any suggestion is greatly appreciated.</p>
  
  <h2><strong>Here's my code:</strong></h2>
  
  <pre><code>List&lt;LatestDataReduced&gt; latestdata = new List&lt;LatestDataReduced&gt;(); 
  //LatestDataReduced is the model of my documents
  foreach (var dep in lrd) 
  {
      foreach (var rec in dep.record)
      {
          var entity = new LatestDataReduced();
          entity.PlatformID = platid;
  
          //fill up data in entity...    
  
          latestdata.Add(entity);
      }
  }
  var connectionString = "mongodb://localhost";
  var client = new MongoClient(connectionString);
  var server = client.GetServer();
  var database = server.GetDatabase("emodnet2");
  var collection = database.GetCollection&lt;LatestDataReduced&gt;("latestdata");
  foreach (var ld in latestdata)
  {
      /*var query = Query.And(Query.EQ("Id", ld.Id), Query.EQ("Date", ld.Date), Query.EQ("Depth", ld.Depth), Query.EQ("PlatformID", ld.PlatformID), Query.EQ("Pressure", ld.Pressure));
      var update = Update.Replace(ld);
      collection.Update(query, update, UpdateFlags.Upsert);*/
  
      collection.Save(ld);
  }
  </code></pre>
  
  <h2><strong>LatestDataReduced class:</strong></h2>
  
  <pre><code>using MongoDB.Bson;
  using MongoDB.Bson.Serialization.Attributes;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace MongoDB.Models
  {
      public class CodeValuePair
      {
          public string Code { get; set; }
          public double Value { get; set; }
      }
  
      public class LatestDataReduced
      {
          //[BsonIgnoreIfDefault]
          public ObjectId Id { get; set; }
          public int PlatformID { get; set; }
          public DateTime Date { get; set; }
          public double Depth { get; set; }
          public List&lt;CodeValuePair&gt; ParamValue { get; set; }
          public double Pressure { get; set; }
          public List&lt;CodeValuePair&gt; ParamValueInfo { get; set; }
          public string Roos { get; set; }
      }
  }
  </code></pre>