class Mongoid::Criteria

Public Instance Methods

as_doc() click to toggle source
# File lib/theusual/mongoid.rb, line 8
def as_doc
  to_a.map &:as_doc
end
Also aliased as: as_docs
as_docs()
Alias for: as_doc
find_in_batches(opts = {}) { |docs| ... } click to toggle source

see apidock.com/rails/ActiveRecord/Batches/find_in_batches

# File lib/theusual/mongoid.rb, line 20
def find_in_batches(opts = {}, &block)
  batch_size = opts[:batch_size] || 1000
  offset = opts[:start] || 0

  loop do
    docs = skip(offset).limit(batch_size).to_a

    if docs.empty?
      break
    else
      yield docs
      offset += batch_size
    end
  end
end
last(n = 1) click to toggle source

can't seem to override Mongoid::Document::last, so put this functionality here

# File lib/theusual/mongoid.rb, line 15
def last(n = 1)
  order(_id: -1).limit(n)
end