BasicDBObject update = new BasicDBObject();
//FIXME should "value" be hardcoded?
//FIXME how to set the initialValue if the document is not present? It seems the inc value is used as initial new value
Integer incrementObject = increment == 1 ? ONE : Integer.valueOf( increment );
this.addSubQuery( "$inc", update, SEQUENCE_VALUE, incrementObject );
DBObject result = currentCollection.findAndModify( query, null, null, false, update, false, true );
Object idFromDB;
idFromDB = result == null ? null : result.get( SEQUENCE_VALUE );
if ( idFromDB == null ) {
//not inserted yet so we need to add initial value to increment to have the right next value in the DB
//FIXME that means there is a small hole as when there was not value in the DB, we do add initial value in a non atomic way