       pluck = refresh
       refresh = false
     @sync(refresh).then =>
+      console.log 'all', @_documents.length
       if pluck then defer.map(@_documents, (d) -> d[pluck]?())
       else @_documents
 

      (document) => document.fetch().yield(false).else(true)
      (document) => @_documents[document.hdkey.index - @offset] = document
      @at(start)
    )

exports = module.exports = Collection


  insert: (definition, data, autosave=true) ->
    return false if @readonly
    @sync().then =>
      document = @at()
      document.definition(@definition(definition))
      .then => document.data(data)
      .then -> document.save() if autosave
      .then => @_documents[document.hdkey.index - @offset] = document

  at: (index=@_documents.length+@offset) ->
    document = @_documents[index-@offset]
