title: MongoDB Java Driver: How to insert into any collection from Java Driver
body: <p>I have a client facing application with a function that takes in 2 arguments as strings, arg1 is the collection, arg 2 is the function, arg 2 is the hash of the object</p>
  
  <p>so in Java I have </p>
  
  <pre><code>foo(String collection, String object):
  </code></pre>
  
  <p>/*and I have my db object from the mongoDB driver
  the collection I want to insert into is "users" */</p>
  
  <pre><code>MongoClient mongoClient = new MongoClient( "localhost" );
  DB db = mongoClient.getDB("mydb");
  </code></pre>
  
  <p>now here is where I am having trouble</p>
  
  <pre><code>db.runCommand({insert : collection (? can i do this),
                 ????}) &lt;- I dont know how to right this and append the object
  </code></pre>
  
  <p>I did a bunch of searching before hand and a lot of the examples I found already had a predefined collection but I need to abstract this.</p>
  
  <p>Any help would be extremely useful, thank you.</p>
  
  <p>UPDATE:</p>
  
  <p>I am not looking for coll.find() java method. I want to visualize someones mongoDB data with a better output than what the shell provides. So I am looking for a very general db.runcommand(string) that can take in an insert/find/findone() whatever is passed in as a string. I can get collection names using runcommand so I understand it on a basic level, but cannot apply specific commands to any user defined collection.</p>