   #
   stop: ->
     if @started
-      @dbInstance.close()
+      @mongoclient.close (err, result) =>
+        if err
+          @owner.log "Closed mongo link with errors : ", err
+        else
+          @owner.log "Closed mongo link"
 
   #
   # @overload h_send(buffer)

  # @private
  #
  h_connectToDatabase: () ->
    #Create the Server and the DB to access mongo
    new mongo.Db(@properties.name, new mongo.Server(@properties.host or 'localhost', @properties.port or 27017), {safe: false}).open (err, dbOpen) =>
      unless err
        @owner.log "debug", "Correctly connect to mongo"
        @dbInstance = dbOpen

        if @properties.user and @properties.password
          @dbInstance.authenticate @properties.user, @properties.password, (err, success) =>
            if err
              @owner.log "error", err

        #Error opening database
      else
        @owner.log "error", "Could not open database"

  #
  # @overload start()

    @start() unless @started

    if @dbInstance isnt undefined
      doc = buffer

      @dbInstance.collection(@properties.collection).save doc, {w:1}, (err, savedDoc) =>
        if err
          @owner.log "error", "Error while saving hMessage in database" + err
    else
      @owner.log "warn", "MongoDB not yet started"

