ruby on rails 很好的跟mongodb进行了结合,gem包:

地址:https://rubygems.org/gems/mongoid

文档:https://docs.mongodb.com/ecosystem/tutorial/ruby-mongoid-tutorial/#ruby-mongoid-tutorial

最新还用的查询 

Model.where(name:/abc/)

 

这个可以查找model表中name字段有abc的所有内容。

分页,可以结合willpage

def self.paginate(options = {})
    options[:page] = options[:page].to_i
    options[:page] = 1 if options[:page] == 0
    options = base_options options
    ::WillPaginate::Collection.create(options[:page], options[:per_page]) do |pager|
      items_count = options[:total_entries] || self.count
      fill_pager_with self.skip(options[:offset]).limit(options[:per_page]), items_count, pager
    end
  end

  def self.base_options(options)
    options[:page] ||= 1
    options[:per_page] ||= 20
    options[:offset] = (options[:page].to_i - 1) * options[:per_page].to_i
    options
  end

  def self.fill_pager_with(medias, size, pager)
    pager.replace medias.to_a
    pager.total_entries = size
  end