def get_many(type, regex=nil, opts={})

      opts = opts.inject({}) { |h, (k, v)| h[k.to_s] = v; h }

      d = dir_for(type)

      return (opts['count'] ? 0 : []) unless File.exist?(d)

      regexes = regex ? Array(regex) : nil

      docs = []
      skipped = 0

      limit = opts['limit']
      skip = opts['skip']
      count = opts['count'] ? 0 : nil

      files = Dir[File.join(d, '**', '*.json')].sort_by { |f| File.basename(f) }
      files = files.reverse if opts['descending']

      files.each do |fn|

        key = File.basename(fn, '.json')

        if regexes.nil? or match?(key, regexes)

          skipped = skipped + 1
          next if skip and skipped <= skip

          doc = get(type, key)
          next unless doc

          if count
            count = count + 1
          else
            docs << doc
          end

          break if limit and docs.size >= limit
        end
      end

      # WARNING : there is a twist here, the filenames may have a different
      #           sort order from actual _ids...

      #docs.sort { |doc0, doc1| doc0['_id'] <=> doc1['_id'] }
        # let's trust filename order

      count ? count : docs
    end
def get_many(type, regex=nil, opts={})

      opts = opts.inject({}) { |h, (k, v)| h[k.to_s] = v; h }

      d = dir_for(type)

      return (opts['count'] ? 0 : []) unless File.exist?(d)

      regexes = regex ? Array(regex) : nil

      docs = []
      skipped = 0

      limit = opts['limit']
      skip = opts['skip']
      count = opts['count'] ? 0 : nil

      files = Dir[File.join(d, '**', '*.json')].sort_by { |f| File.basename(f) }
      files = files.reverse if opts['descending']

      files.each do |fn|

        key = File.basename(fn, '.json')

        if regexes.nil? or match?(key, regexes)

          skipped = skipped + 1
          next if skip and skipped <= skip

          doc = get(type, key)
          next unless doc

          if count
            count = count + 1
          else
            docs << doc
          end

          break if limit and docs.size >= limit
        end
      end

      # WARNING : there is a twist here, the filenames may have a different
      #           sort order from actual _ids...

      #docs.sort { |doc0, doc1| doc0['_id'] <=> doc1['_id'] }
        # let's trust filename order

      count ? count : docs
    end
Given a type, this method will return an array of all the documents for
 that type.

 A optional second parameter may be used to select, based on a regular
 expression, which documents to include (match on the key '_id').

 Will return an empty Hash if there is no documents for a given type.

 == opts

 :skip and :limit are understood (pagination).

 If :count => true, the query will simply return the number of documents
 that matched.