public static void Main()
BsonDocument doc = new BsonDocument
"Meeting", new BsonDocument
"Session", new BsonDocument
ClientCode(doc, "Meeting.Session.Time");
Console.WriteLine("---");
ClientCode(doc, "Meeting.Session.Time2");
public static void ClientCode(BsonDocument doc, string key)
bool hasKey = doc.TryGetChainedValue(key, out BsonValue @value);
Console.WriteLine($"Is Key existed: {hasKey}");
Console.WriteLine($"Value: {@value}");
public static class BsonDocumentExtensions
public static bool TryGetChainedValue(this BsonDocument doc, string key, out BsonValue @value)
if (String.IsNullOrWhiteSpace(key))
string[] chainedKeys = key.Split(".").ToArray();
foreach (var chainKey in chainedKeys)
hasKey = doc.TryGetValue(chainKey, out @value);
hasKey = (@value.ToBsonDocument()).TryGetValue(chainKey, out @value);