title: Use of MongoJack and updateById
body: <p>I am having a problem with the usage of MongoJack and updateById method. </p>
  
  <p>In the javadoc from MongoJack, it states that the method updateById(K, T) (<a href="http://mongojack.org/apidocs/org/mongojack/JacksonDBCollection.html#updateById(K,%20T)" rel="nofollow">link to javadoc</a>) can be used with K as the key and T as the object to save. However, the following code and test shows that this is not the case. The full source code can be found at Github: <a href="https://github.com/nilsmagnus/mongojackupdatebyid/" rel="nofollow">https://github.com/nilsmagnus/mongojackupdatebyid/</a>.</p>
  
  <p>Object to save:</p>
  
  <pre><code>package no.nils.mongoupdate;
  
    public class Scenario {
    public String _id;
    public String name;
  
    public Scenario(String name) {
      this.name = name;
    }
  
    public String get_id() {
      return _id;
    }
  
    public String getName() {
      return name;
    }
  }
  </code></pre>
  
  <p>Updating class:</p>
  
  <pre><code>package no.nils.mongoupdate;
  
  import org.mongojack.JacksonDBCollection;
  import org.mongojack.WriteResult;
  import com.mongodb.DB;
  import com.mongodb.DBCollection;
  
  class ScenarioStorage {
  private JacksonDBCollection&lt;Scenario, String&gt; scenarioCollection;
  
  public ScenarioStorage(DB db) {
      DBCollection dbCollection = db.getCollection("scenario");
      scenarioCollection = JacksonDBCollection.wrap(dbCollection, Scenario.class, String.class);
  }
  
  public void update(Scenario scenario) {
      WriteResult&lt;Scenario, String&gt; writeResult = scenarioCollection.updateById(scenario._id, scenario);
      if (writeResult.getError() != null) throw new RuntimeException(writeResult.getError());
  }
  
  public String saveNewScenario(Scenario scenario) {
      WriteResult&lt;Scenario, String&gt; writeResult = scenarioCollection.insert(scenario);
      if (writeResult.getError() != null) throw new RuntimeException(writeResult.getError());
      return writeResult.getSavedId();
  }
  
  
  public Scenario getScenario(String id) {
      return scenarioCollection.findOneById(id);
  }
  }
  </code></pre>
  
  <p>Test that shows the failure:</p>
  
  <pre><code>package no.nils.mongoupdate;
  
  import java.net.UnknownHostException;
  
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertNotNull;
  
  import org.junit.Before;
  import org.junit.Test;
  import com.mongodb.DB;
  import com.mongodb.MongoClient;
  
  public class ScenarioStorageTest {
  
  private ScenarioStorage storage;
  
  @Before
  public void createDb() throws UnknownHostException {
      MongoClient mongoClient = new MongoClient("localhost", 27017);
      DB db = mongoClient.getDB("junittest");
      storage = new ScenarioStorage(db);
  }
  
  @Test
  public void shouldUpdateNameAfterUpdate() {
      Scenario scenario = new Scenario("first");
      final String id = storage.saveNewScenario(scenario);
      scenario._id = id;
      scenario.name = "newname";
      storage.update(scenario);
      Scenario updated = storage.getScenario(id);
      assertNotNull("Stored object should have been fetched.", updated.name);
      assertEquals("The stored object should now have the name 'newname'.", updated.name, "newname");
  }
  }
  </code></pre>
  
  <p>The test fails on the first assertion. Please advise if I have misunderstood the javadoc for mongojack or any other errors I may have made. </p>