If I have loaded the following json into a BSON document:
{
"contact":
{ "firstname":"Pete"
,"surname":"Jones"
,"company":[{"name":"Virgin","notes":"some virgin notes"},{"name":"IBM","notes":"a great big IT company"}]
}
,"response":
{
"_id":"123"
,"profileid":"567"
,"localdate":"12 Apr 2011 14:34:23"
}
}
I can detect if a given element exists using this:
if (suppliedDoc.Contains("_id"))
but I can’t address nested element using this syntax:
if (suppliedDoc.Contains("response._id"))
What is the correct syntax for addressing nested elements? And is there a better way to detect the existence of root or nested elements? I am using the official C# driver. Thanks.
You’re probably after something like
which I agree is kind of awkward.
It wouldn’t take too much effort though to write an extension method on
BsonDocumentthat takes a string with punctuations in it, splits it by the., and drills down using the method shown above.