     @_closeAfterRequest = true
 
     if @db isnt null
+      if @collection.object isnt null
+        @collection = name: null, object: null
+
       @db.close()
       @db = null
-
-    if @collection.object isnt null
-      @collection = name: null, object: null
 
     @
 


    after = (->) if after is null

    @getInstance table, (db, collection) =>
      collection.count params, (error, results) =>
        if error
          console.log 'Error with fetching counts: ' + error

  getInstance: (table, after) ->
    throw new Error 'The database name must be configured (options.db)' unless @options.db?

    if @db isnt null and @db.state is 'connected'
      @getCollection table, after
    else
      instance = new Db @options.db, new Server @options.host, @options.port, {}

