Adding an array to a mongodb document fails with precondition failed: !(bson->flags & BSON_FLAG_IN_CHILD)

Tried to do it based on the official documentation. Here is the code, I’m trying to add a few items to an array:

  auto in_array = bsoncxx::builder::stream::document{}
        << "$set" << open_document << call_id_key << call_id << close_document << "$push"
        << open_document << transcription_key
        << open_array << open_document << direction_key << "INBOUND" << text_key 
        << transcript << confidence_key << confidence
        << start_time_key << start_time << end_time_key << end_time
        << "words" << open_array;

  for (const auto& word_info : words) {
    in_array = in_array << open_document << "word" << word_info.first <<
        "confidence" << word_info.second << close_document;  // Assertion happens here
  }

  bsoncxx::document::value doc = in_array << close_array << close_document << close_array << close_document << finalize;
  std::cout << bsoncxx::to_json(doc.view()) << std::endl;