class EM::Mongo::Collection

Public Instance Methods

afind(*args)

afind is the old (async) find afind_one is rewritten to call afind find is sync, using a callback on the cursor find_one is sync, by calling find and taking the first element. first is sync, an alias for find_one

Alias for: find
afind_one(spec_or_object_id=nil, opts={}) click to toggle source

need to rewrite afind_one manually, as it calls 'find' (reasonably expecting it to be what is now known as 'afind')

# File lib/em-synchrony/em-mongo.rb, line 73
def afind_one(spec_or_object_id=nil, opts={})
  spec = case spec_or_object_id
         when nil
           {}
         when BSON::ObjectId
           {:_id => spec_or_object_id}
         when Hash
           spec_or_object_id
         else
           raise TypeError, "spec_or_object_id must be an instance of ObjectId or Hash, or nil"
         end
  afind(spec, opts.merge(:limit => -1)).next_document
end
Also aliased as: afirst
afirst(spec_or_object_id=nil, opts={})
Alias for: afind_one
find(*args) click to toggle source
# File lib/em-synchrony/em-mongo.rb, line 63
def find(*args)
  f = Fiber.current
  cursor = afind(*args)
  cursor.to_a.callback{ |res| f.resume(res) }
  Fiber.yield
end
Also aliased as: afind, afind
find_one(selector={}, opts={}) click to toggle source
# File lib/em-synchrony/em-mongo.rb, line 88
def find_one(selector={}, opts={})
  opts[:limit] = 1
  find(selector, opts).first
end
Also aliased as: first
first(selector={}, opts={})
Alias for: find_one