 mongoDB = new MongoDB config
 module.exports = mongoDB
 
-# options =
-#    username : "gokment"   
-#    dbName    : "dlskdlskdlsk"
+#options =
+#   username : "gokment"   
+#   dbName    : "dlskdlskdlskdlsjdlsjdlkdkddkdkd"
 
 #mongoDB.createDatabase options,(err,res)->
 #  console.log err,res
 
-# mongoDB.fetchDatabaseList options,(res)->
-#   console.log res
+#mongoDB.fetchDatabaseList options,(err,res)->
+#  console.log res
 #dbs =  ['gokment_c219e4c7','gokment_df539bb7']
 #for db in dbs
 #  do (db)->


    db = new mongo.Db dbConf.dbName, @server

    db.open (err,db)=>
      if err?
        log.error "[ERROR] can't open database #{dbConf.dbName}: #{err}"
        callback? "[ERROR] can't open database #{dbConf.dbName}: #{err}"
      else
        db.admin().authenticate @mongoUser, @mongoPass,(err,result)=>
          if err?
            log.error "[ERROR] can't authenticate with admin credentials: #{err}"
            callback?  "[ERROR] can't authenticate with admin credentials: #{err}"
          else
            db.addUser dbConf.dbUser,dbConf.dbPass,(err,res)->
              log.debug err,res
              db.authenticate dbConf.dbUser,dbConf.dbPass,(err,res)->
                if err?
                  log.error "[ERROR] can't create user #{dbConf.dbUser} and database #{dbConf.dbName}: #{err}"
                  callback? "[ERROR] can't create user #{dbConf.dbUser} and database #{dbConf.dbName}: #{err}"
                else
                  log.debug res
                  log.info "[OK] user #{dbConf.dbUser} and database #{dbConf.dbName} has been created"
                  log.info dbConf
                  callback? null,dbConf

  changePassword : (options,callback)->


#log     = log4js.addAppender log4js.fileAppender(logFile), "[MongoDBApi]"
log     = log4js.getLogger('[MongoDBApi]')

class AccessError extends Error
  constructor:(@message)->

class KodingError extends Error
  constructor:(message)->
    return new KodingError(message) unless @ instanceof KodingError
    Error.call @
    @message = message
    @name = 'KodingError'

class MongoDB

  appendKodingUsername = (username, str)->
