There is an awkward inconsistency in the operator[] interface for bsoncxx::document::element and bsoncxx::document::array.
If element::operator[] or array::operator[] is called and a matching element is not found, we return an invalid element.
Similarly, if you call element::operator[] (either overload) and a matching element is not found, we also return an invalid element, as long as the type of the current element is document or array.
However, if you call element::operator[] (either overload) on something that is neither a document nor an array, an exception is thrown.
This means that a statement like:
foo[a][b][c][d]
May either throw or return an invalid element, depending on the shape of the document foo.
This is pretty hard to handle. We should make it either throw, always, on a missing element, or degrade to an invalid element, always.