def bulk_save(docs = nil, opts = {})
      opts = { :use_uuids => true, :all_or_nothing => false }.update(opts)
      if docs.nil?
        docs = @bulk_save_cache
        @bulk_save_cache = []
      end
      if opts[:use_uuids]
        ids, noids = docs.partition{|d|d['_id']}
        uuid_count = [noids.length, @server.uuid_batch_count].max
        noids.each do |doc|
          nextid = server.next_uuid(uuid_count) rescue nil
          doc['_id'] = nextid if nextid
        end
      end
      request_body = {:docs => docs}
      if opts[:all_or_nothing]
        request_body[:all_or_nothing] = true
      end
      results = connection.post "#{path}/_bulk_docs", request_body
      docs_by_id = Hash[docs.map { |doc| [doc['_id'], doc] }] unless docs.nil?
      results.each { |r| docs_by_id[r['id']]['_rev'] = r['rev'] if r['ok'] } unless results.nil?
      results
    end
def bulk_save(docs = nil, opts = {})
      opts = { :use_uuids => true, :all_or_nothing => false }.update(opts)
      if docs.nil?
        docs = @bulk_save_cache
        @bulk_save_cache = []
      end
      if opts[:use_uuids]
        ids, noids = docs.partition{|d|d['_id']}
        uuid_count = [noids.length, @server.uuid_batch_count].max
        noids.each do |doc|
          nextid = server.next_uuid(uuid_count) rescue nil
          doc['_id'] = nextid if nextid
        end
      end
      request_body = {:docs => docs}
      if opts[:all_or_nothing]
        request_body[:all_or_nothing] = true
      end
      results = connection.post "#{path}/_bulk_docs", request_body
      docs_by_id = Hash[docs.map { |doc| [doc['_id'], doc] }] unless docs.nil?
      results.each { |r| docs_by_id[r['id']]['_rev'] = r['rev'] if r['ok'] } unless results.nil?
      results
    end
POST an array of documents to CouchDB. If any of the documents are
 missing ids, supply one from the uuid cache.

 If called with no arguments, bulk saves the cache of documents to be bulk saved.