@Override
  public Output update(String id, Map<String, Object> deltas) {
    DBUpdate.Builder update = new DBUpdate.Builder();
    for (Map.Entry<String, Object> fields : deltas.entrySet())
      update = update.set(fields.getKey(), fields.getValue());

    return coll.findAndModify(DBQuery.is("_id", id), update);
  }
 public boolean updateGameLog(String pbfId, String oldUsername, String newUsername) {
   List<GameLog> gameLogs =
       gameLogCollection.find(DBQuery.is("pbfId", pbfId).is("username", oldUsername)).toArray();
   for (GameLog gl : gameLogs) {
     gl.setUsername(newUsername);
     gameLogCollection.updateById(gl.getId(), gl);
   }
   return !gameLogs.isEmpty();
 }
  public int deleteMailContext(String workflowId) {
    try {
      this.db = getConnection();
      this.dbCollectionMail = this.db.getCollection(this.config.getMailCollection());
      JacksonDBCollection<MailContext, String> coll;
      coll = JacksonDBCollection.wrap(this.dbCollectionMail, MailContext.class, String.class);

      if (coll.getCount(DBQuery.is("_id", workflowId)) != 0) {
        coll.removeById(workflowId);
      } else {
        return NOT_FOUND_IN_DATABASE;
      }
    } catch (UnknownHostException ex) {
      Logger.getLogger(DaoMailContext.class.getName()).log(Level.SEVERE, null, ex);
      return ERROR_DELETING_DATA;
    }
    return DATA_SUCCESSFULLY_DELETED;
  }
  /*=================================================================
  | Function storeMailContext
  | Propósito: Store the mail settings for a particular worlflow
  | Return values: ERROR / SUCCES code (int)
  ===================================================================*/
  public int storeMailContext(MailContext mailContext) {
    try {
      this.db = getConnection();
      this.dbCollectionMail = this.db.getCollection(this.config.getMailCollection());
      JacksonDBCollection<MailContext, String> coll;
      coll = JacksonDBCollection.wrap(this.dbCollectionMail, MailContext.class, String.class);

      // if exist update
      if (coll.getCount(DBQuery.is("_id", mailContext.getAsociatedWorflow())) != 0) {
        coll.updateById(mailContext.getAsociatedWorflow(), mailContext);
      } else {
        coll.insert(mailContext);
      }
    } catch (UnknownHostException ex) {
      Logger.getLogger(DaoMailContext.class.getName()).log(Level.SEVERE, null, ex);
      return ERROR_STORING_DATA;
    }
    return DATA_SUCCESSFULLY_STORED;
  }
 public List<GameLog> getGameLogsBelongingToPlayer(String pbfId, String username) {
   return gameLogCollection.find(DBQuery.is("pbfId", pbfId).is("username", username)).toArray();
 }
 public List<GameLog> getGameLogs(String pbfId) {
   return gameLogCollection.find(DBQuery.is("pbfId", pbfId)).toArray();
 }