You have two main choices for iterating over the elements in a
BsonDocument:
BsonDocument document;
foreach (BsonElement element in document) {
// process element (using element.Name and element.Value)
}
or:
foreach (BsonValue value in document.Values) {
// process value
}
The difference is in the data type of the iteration variable.
To figure out the type of each value you can do things like:
if (element.Value.IsBsonDocument) { ... }
if (value.IsBsonDocument) { ... }
if (value is BsonDocument) { ... }
switch (value.BsonType) {
case BsonType.Document: ...
case BsonType.Array: ...
etc...
}
Let me know if I didn't completely answer your question.