@Override public void saveModel(Server model) { BasicDBObject dbServer = new BasicDBObject(); dbServer.put("updated_at", model.getUpdated_at()); if (model.getNode() != null) { dbServer.put("node_id", model.getNode().getId().toString()); } dbServer.put("port", model.getPort()); dbServer.put("container", model.getContainerId()); dbServer.put("players", new BasicDBObject(model.getPlayers())); BasicDBList metaDataList = new BasicDBList(); for (Map.Entry<String, ServerMetaData> metaDataEntry : model.getMetaData().entrySet()) { DBObject dbMetaData = new BasicDBObject(); dbMetaData.put("_id", metaDataEntry.getValue().getId()); dbMetaData.put("created_at", metaDataEntry.getValue().getCreated_at()); dbMetaData.put("updated_at", metaDataEntry.getValue().getUpdated_at()); dbMetaData.put("key", metaDataEntry.getValue().getKey()); dbMetaData.put("value", metaDataEntry.getValue().getValue()); metaDataList.add(dbMetaData); } dbServer.put("metaData", metaDataList); dbServer.put("number", model.getNumber()); getDatabase() .updateDocument( "servers", new BasicDBObject("_id", model.getId()), new BasicDBObject("$set", dbServer)); }