title: How to check if key exists in BsonDocument or not using Mongodb C# driver?
body: <p>I am receiving data <code>(BsonDocument)</code> from <code>mongodb</code> using a <code>C#</code> driver like this:</p>
  
  <pre><code>{ 
   "_id":ObjectId("5c8730688a247070ca5e4a15"),
   "visitorEmail":"UnRegistered",
   "visitorName":"Guest040704",
   "agentEmail":"salman@blauda.com",
   "sessionid":"5c86e0f88a247070ca5e48e6",
   "createdOn":"2019-03-12T04:07:04.455Z",
   "state":3,
   "messages":[ 
  
    ],
  "messageReadCount":0,
  "lastMessage":{ 
     "_id":ObjectId("5c8730688a247070ca5e4a16"),
      "from":"MEHAK",
      "to":"Guest040704",
      "body":"Hello.. How may i Help You ?",
      "cid":ObjectId("5c8730688a247070ca5e4a15"),
      "date":"2019-03-12T04:07:04.455Z",
      "type":"Agents",
       "attachment":false,
       "filename":null
     },
   "entertained":true,
   "endingDate":"2020-01-15T05:47:37.170Z"
  }
  </code></pre>
  
  <p>Now I want to check if the key "assigned_to" exists in this document or not. So i tried this:</p>
  
  <pre><code>convObject.TryGetValue("assigned_to", out isAssignedToExist);
  Console.WriteLine("is assigned to ---- : "+isAssignedToExist);
  </code></pre>
  
  <p>I am getting an error like this instead of the result whether key exists or not:</p>
  
  <pre><code>ErorrSystem.Collections.Generic.KeyNotFoundException: Element 'assigned_to' not found.at 
  MongoDB.Bson.RawBsonDocument.GetValue(String name) at 
  sqs_processor.QueueService.ExecuteAsync(CancellationToken stoppingToken) in 
  D:\OfficeProjects\beelinksanalytics\Services\queueService.cs:line 100
  </code></pre>