Create document with arrays from nested keys

Hi,

i am trying to create a generic document that is specified by a nested key like for example: “evaluateResult.data.measurements.0.value” and put a value in the last specified field.
Where the numbers denote an array index and string-identifiers denote sub-objects.

I thought of something like this:

std::vector<std::string> subKeys = {"evaluateResult","data","measurements","0","value"};
uint32_t myValue = 42;

bsoncxx::builder::stream::document doc_builder{};

for (int i = 0; i < subKeys.size() - 1; i++) {
	if (subKeys.at(i+1).find_first_not_of("0123456789") == std::string::npos)
	{
		doc_builder << subKeys.at(i) << bsoncxx::builder::stream::open_array;
	}
	else
	{
		doc_builder << subKeys.at(i) << bsoncxx::builder::stream::open_document;
	}
}
doc_builder << subKeys.back() << myValue;

for (int i = subKeys.size() - 1; i > 0; i--) {
	if (subKeys.at(i + 1).find_first_not_of("0123456789") == std::string::npos)
	{
	doc_builder << bsoncxx::builder::stream::close_array;
	}
	else 
	{
	doc_builder << bsoncxx::builder::stream::close_document;
	}
}

Without the array part this works great.

But when I try to compile this version with the array part I get the following error:

Error C2679 binary ‘<<’: no operator found which takes a right-hand operand of type ‘const bsoncxx::v_noabi::builder::stream::close_array_type’ (or there is no acceptable conversion)

Is there a way to achieve my goal using the stream builder?