title: How to generate Mongodb documents recursively using mongocxx c++ driver?
body: <p>How to generate Mongodb documents recursively using mongocxx c++ driver?
   1. I use mongocxx c++ driver v.3 and c++11.
   2. Here is my main.cpp method, which parses hex string and generate mongocxx code like this:
  <strong>console:$</strong> ./main dissect 0x160301012c01000128030340c70e243001b96d8c
  and the output: </p>
  
  <pre><code>    &lt;&lt; "MainType" &lt;&lt; bsoncxx::builder::stream::open_document
      &lt;&lt; "TLSRecord" &lt;&lt; bsoncxx::builder::stream::open_document
          &lt;&lt; "type"&lt;&lt; "16"
          &lt;&lt; "version"&lt;&lt; "0301"
          &lt;&lt; "length"&lt;&lt; "012C"
          &lt;&lt; "hsMsg" &lt;&lt; bsoncxx::builder::stream::open_document
              &lt;&lt; "type"&lt;&lt; "01"
              &lt;&lt; "length"&lt;&lt; "000128"
              &lt;&lt; "clientHello" &lt;&lt; bsoncxx::builder::stream::open_document
                  &lt;&lt; "version"&lt;&lt; "0303"
                  &lt;&lt; "random"&lt;&lt; "40C70E243001B96D8C"
                  &lt;&lt; "session_id_length"&lt;&lt; ""
              &lt;&lt; bsoncxx::builder::stream::close_document
          &lt;&lt; bsoncxx::builder::stream::close_document
      &lt;&lt; bsoncxx::builder::stream::close_document
  </code></pre>
  
  <ol start="3">
  <li><p>After this I needed to push it in mongodb.</p>
  
  <ul>
  <li><p>Call connection method from dissect method form main.cpp
  <a href="https://i.stack.imgur.com/8TL20.png" rel="nofollow noreferrer">Call mongodb connection after hex string parsing</a></p></li>
  <li><p>Create the mongodbConnection:</p></li>
  <li><p>Call MongodbMapper to map generated code to db</p></li>
  <li><p>Call GenerateDocument to generate it automatically
  <a href="https://i.stack.imgur.com/ufWei.png" rel="nofollow noreferrer">Connect -> Mapp -> Generate -> Insert</a></p></li>
  </ul></li>
  <li><p>And Here I got stacked, got error when try to compile it.</p>
  
  <p><code>src/MongodbMapper.cpp:76:6: note: candidate function not viable: no known conversion from</code>   <code>'bsoncxx::v_noabi::builder::stream::key_context&lt;bsoncxx::v_noabi::builder::stream::key_context&lt;bsoncxx::v_noabi::builder::stream::closed_context&gt; &gt;' to</code> 
  <code>'bsoncxx::builder::stream::document &amp;' for 3rd argument
      void generateDocument(DataUnit&amp; node, int level, bsoncxx::builder::stream::document&amp; doc) {</code></p></li>
  </ol>