title: Remove document by id field in mongodb using C#
body: <p>I am trying to delete the document by id, which is of type ObjectId, I do have converted the string to ObjectId and passed as parameter to remove from collection, but I am not able to delete the record.</p>
  
  <p>I don't know what is the actuall reason behind, Looking for solution, below is my code sample:</p>
  
  <pre><code> public void DeleteRecords(string objectID)
          {
              try
              {
                  // Create server settings to pass connection string, timeout, etc.
                  MongoServerSettings settings = new MongoServerSettings();
                  settings.Server = new MongoServerAddress("localhost", 27017);
                  // Create server object to communicate with our server
                  MongoServer server = new MongoServer(settings);
  
                  MongoDatabase myDB = server.GetDatabase("DemoMongoDB");
  
                  MongoCollection&lt;BsonDocument&gt; records = myDB.GetCollection&lt;BsonDocument&gt;("Records");
                  //var query = Query&lt;Records&gt;.EQ(fd =&gt; fd._id, ObjectId.Parse(name));
                  var query = Query&lt;Records&gt;.EQ(e =&gt; e._id, new BsonObjectId(objectID));
                  records.Remove(query);
  
              }
              catch (Exception ex)
              {
  
              }
          }
  </code></pre>