我正在使用这样的(BsonDocument)
驱动程序接收数据:mongodb
C#
{
"_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"
}
现在我想检查这个文档中是否存在键“assigned_to”。所以我尝试了这个:
convObject.TryGetValue("assigned_to", out isAssignedToExist);
Console.WriteLine("is assigned to ---- : "+isAssignedToExist);
我收到这样的错误,而不是密钥是否存在的结果:
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