title: How to convert mongo.InsertOneResult's InsertedID to []byte
body: <p>Hi all I am struggling to convert the InsertedID of an InsertOne() Operation to a byte slice*. I am using this mongoDB client library <a href="https://github.com/mongodb/mongo-go-driver" rel="nofollow noreferrer">https://github.com/mongodb/mongo-go-driver</a></p>
  
  <hr>
  
  <p>So far I have tried to use TypeAssertion directly like this:</p>
  
  <pre><code>res.InsertedID.([]byte)
  </code></pre>
  
  <p>which compiles, but results in the following error during the assertion:</p>
  
  <blockquote>
    <p>panic: interface conversion: interface {} is primitive.ObjectID, not []uint8</p>
  </blockquote>
  
  <p>I have also tried to use multiple TypeAssertions or the <code>[]byte()</code> function directly, but could not get it to compile</p>
  
  <hr>
  
  <p>*byte slice is in this case desired because I am using gRPC, which limits the possible types I can use for return values.</p>