Class: EM::Mongo::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/em-synchrony/em-mongo.rb

Instance Method Summary collapse

Instance Method Details

#afindObject


62
63
64
65
66
67
# File 'lib/em-synchrony/em-mongo.rb', line 62

def find(*args)
  f = Fiber.current
  cursor = afind(*args)
  cursor.to_a.callback{ |res| f.resume(res) }
  Fiber.yield
end

#afind_one(spec_or_object_id = nil, opts = {}) ⇒ Object Also known as: afirst

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


73
74
75
76
77
78
79
80
81
82
83
84
85
# 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

#find(selector = {}, opts = {}) ⇒ Object


63
64
65
66
67
68
# 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

#find_one(selector = {}, opts = {}) ⇒ Object Also known as: first


88
89
90
91
# File 'lib/em-synchrony/em-mongo.rb', line 88

def find_one(selector={}, opts={})
  opts[:limit] = 1
  find(selector, opts).first
end