title: mongodb + java giving 'ok' should never be null , when DB name is injected via spring
body: <p>Mongodb version             - mongodb-win32-i386-2.4.8<br>
  mongodb java driver version - mongo-java-driver-2.12.0</p>
  
  <p>Code</p>
  
  <pre><code>    DB db = mongoClient.getDB(getDbName());
      DBCollection collection = db.getCollection(getCollectionName());
      BasicDBObject dbObject = new BasicDBObject();
      dbObject.put("name","John Doe");
      collection.save(dbObject);
      mongoClient.close();
  </code></pre>
  
  <p>Stacktrace</p>
  
  <blockquote>
    <p>Jan 05, 2014 7:26:50 PM com.mongodb.DBPortPool gotError WARNING:
    emptying DBPortPool to localhost/127.0.0.1:27017 b/c of error
    java.lang.IllegalArgumentException: 'ok' should never be null...  at
    com.mongodb.CommandResult.ok(CommandResult.java:43)   at
    com.mongodb.CommandResult.throwOnError(CommandResult.java:109)    at
    com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:102)
      at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:142)  at
    com.mongodb.DBTCPConnector.say(DBTCPConnector.java:115)   at
    com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:248)   at
    com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)   at
    com.mongodb.DBCollection.insert(DBCollection.java:148)    at
    com.mongodb.DBCollection.insert(DBCollection.java:91)     at
    com.mongodb.DBCollection.save(DBCollection.java:810)  at
    com.mongodb.DBCollection.save(DBCollection.java:786)</p>
  </blockquote>
  
  <p>Mongod console gives the below trace</p>
  
  <blockquote>
    <p>Sun Jan 05 19:38:08.289 [initandlisten] connection accepted from
    127.0.0.1:50112  #5 (1 connection now open) Sun Jan 05 19:38:08.300 [conn5] assertion 16256 Invalid ns [</p>
  
  <pre><code>                                    tinyblogdb
  
                      .$cmd] ns:
  
                                      tinyblogdb
  
                      .$cmd query:{ getlasterror: 1 } Sun Jan 05 19:38:08.300 [conn5]       ntoskip:0 ntoreturn:-1 Sun Jan 05 19:38:08.300
  </code></pre>
    
    <p>[conn5] end connection 127.0.0.1:50112 (0 connections no w open)</p>
  </blockquote>
  
  <p>Any idea why this happens ? </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>If I hardcode the db name to the variable 'dbn' , the data gets inserted successfully , what I tried before was setter injection with spring in the method <strong>getDbName()</strong> , the below code works ! Now I am super curious why it doesn't work , when I inject the dbName ?</p>
  
  <pre><code>    String dbn = "tinyblogdb";
      MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
      DB db = mongoClient.getDB(dbn);
      DBCollection collection = db.getCollection(getCollectionName());
      BasicDBObject dbObject = new BasicDBObject();
      dbObject.put("name","John Doe");
      collection.save(dbObject);
  </code></pre>