title: How to connect to MongoDB in Java without specifying database name in the URL?
body: <p>I am using the following mongodb driver.</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
      &lt;artifactId&gt;mongo-java-driver&lt;/artifactId&gt;
      &lt;version&gt;3.0.2&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Here's how I connect</p>
  
  <pre><code>String textUri = "mongodb://&lt;username&gt;:&lt;password&gt;@ds027155.mlab.com:27155/";
  MongoClientURI uri = new MongoClientURI(textUri);
  MongoClient m = new MongoClient(uri);
  </code></pre>
  
  <p>I get the error. However if I mention database name</p>
  
  <pre><code>String textUri = "mongodb://&lt;username&gt;:&lt;password&gt;@ds027155.mlab.com:27155/&lt;db-name&gt;";
  </code></pre>
  
  <p>It works without any issue.. Acutally I want to list all the databases present on the server.
  How do I do I mention uri without specifying the database name?</p>
  
  <p>Also how do I list only user defined collections present in the DB.</p>
  
  <pre><code>MongoDatabase db = m.getDatabase("standupmeetingnotes");
  
  ListCollectionsIterable&lt;Document&gt; listColl = db.listCollections();
  
  MongoIterable&lt;String&gt; colls = db.listCollectionNames();
  
  for (String s : colls) {
      System.out.println(s);
  }
  </code></pre>
  
  <p>It prints <strong>objectlabs-system</strong>,
  <strong>objectlabs-system.admin.collections</strong>,
  <strong>system.indexes</strong> also which are system defined collections apart from user defined ones.</p>
  
  <p>Any way I will be able to omit those?</p>
  
  <p>Thanks.</p>