Class: Monga::BlockCursor
Constant Summary
Constants inherited
from Cursor
Cursor::CLOSED_CURSOR, Cursor::CLOSE_TIMEOUT, Cursor::CURSORS
Instance Attribute Summary
Attributes inherited from Cursor
#cursor_id
Instance Method Summary
collapse
Methods inherited from Cursor
batch_kill, #batch_size, create, #explain, #flag, #hint, #initialize, #kill, #limit, #mark_to_kill, #skip, #sort
Constructor Details
This class inherits a constructor from Monga::Cursor
Instance Method Details
#all ⇒ Object
276
277
278
279
280
281
282
|
# File 'lib/monga/cursor.rb', line 276
def all
documents = []
each_batch do |batch|
documents += batch
end
documents
end
|
#each_batch ⇒ Object
248
249
250
251
252
253
|
# File 'lib/monga/cursor.rb', line 248
def each_batch
begin
batch, more = next_batch
yield batch if more || batch
end while more
end
|
#each_doc ⇒ Object
Also known as:
each_document
268
269
270
271
272
273
|
# File 'lib/monga/cursor.rb', line 268
def each_doc
begin
doc, more = next_doc
yield doc if more || doc
end while more
end
|
#first ⇒ Object
284
285
286
287
|
# File 'lib/monga/cursor.rb', line 284
def first
resp = limit(1).all
resp.first
end
|
#next_batch ⇒ Object
241
242
243
244
245
246
|
# File 'lib/monga/cursor.rb', line 241
def next_batch
get_more(get_batch_size) do |err, batch, more|
raise(err) if err
return [batch, more]
end
end
|
#next_doc ⇒ Object
Also known as:
next_document
255
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/monga/cursor.rb', line 255
def next_doc
if doc = @fetched_docs.shift
[doc, more?]
else
batch, more = next_batch
@fetched_docs = batch
doc = @fetched_docs.shift
m = more || @fetched_docs.any?
return [doc, m]
end
end
|