title: Store byte[] in MongoDB using Java
body: <p>I insert a document into a collection with a field of byte[]. When I query the inserted document to get that field, it returns a different byte[]. How do I fix that?</p>
  
  <pre><code>byte[] inputBytes = ...
  
  MongoCollection&lt;Document&gt; collection = _db.getCollection("collectionx");
  Document doc = new Document("test", 1).append("val", inputBytes);
  collection.insertOne(doc.getDocument());
  
  MongoCursor&lt;Document&gt; result = collection.find(eq("test", 1)).iterator();
  Document retrived_doc = cursor.next();
  cursor.close();
  
  byte[] outputBytes = ((Binary)retrived_doc.get("val")).getData();
  
  // inputBytes = [B@719f369d
  // outputBytes = [B@7b70cec2
  </code></pre>