Converting a BSON document containing an array to JSON, removes the array from the converted JSON (C++) Converting a BSON document containing an array to JSON, removes the array from the converted JSON (C++) mongodb mongodb

Converting a BSON document containing an array to JSON, removes the array from the converted JSON (C++)


I believe the problem is here: get_value().get_document(). Try making that say get_value().get_array() instead. Also note that you should be checking the type of the value returned by get_value before calling any methods on it. This is working more by good luck than by good design. The reason that you are seeing a literal zero there is because BSON arrays are represented as documents with integral keys. You have, effectively, cast an array to a document, so it is printing as a document with numeric keys, instead of an array as intended.