From d1c98dfc99c0dd5397d99ff5f0dc7eee61b9a056 Mon Sep 17 00:00:00 2001 From: Abylay Ospan Date: Fri, 14 Dec 2018 14:42:31 -0500 Subject: [PATCH] Fix embedded doc exception with new mongo-cxx With modern mongo-cxx (tested on 3.3.1) we have exception while using embedded documents: terminate called after throwing an instance of 'bsoncxx::v_noabi::exception' what(): can't convert builder to a valid view: unmatched key For example: { "name" : "Jenny", "contact_info" : { "type" : "home" } } we have called twice: 1. for "contact_info" key 2. for "contact_info.type" key we can't call key_view/key_owned twice. Otherwise we receive exception as described above. Signed-off-by: Abylay Ospan --- src/boson/bson_archiver.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/boson/bson_archiver.hpp b/src/boson/bson_archiver.hpp index e590cb4..e036eea 100644 --- a/src/boson/bson_archiver.hpp +++ b/src/boson/bson_archiver.hpp @@ -394,7 +394,8 @@ class BSONOutputArchive : public cereal::OutputArchive { } else { // Set the key of this element to the name stored by the archiver. if (!_dotNotationMode || _embeddedNameStack.empty() || _arrayNestingLevel > 0) { - _bsonBuilder.key_view(_nextName); + if (!isNewNode) + _bsonBuilder.key_view(_nextName); } else { // If we are in dot notation mode and we're not nested in array, build the name of // this key.