Class: Monga::Protocol::Query

Inherits:
Request
  • Object
show all
Defined in:
lib/monga/protocol/query.rb

Constant Summary collapse

FLAGS =
{
  tailable_cursor: 1,
  slave_ok: 2,
  no_cursor_timeout: 4,
  await_data: 5,
  exhaust: 6,
  partial: 7,
}

Constants inherited from Request

Request::OP_CODES

Instance Attribute Summary

Attributes inherited from Request

#connection, #request_id

Instance Method Summary collapse

Methods inherited from Request

#callback_perform, #command, #header, #initialize, #parse_response, #perform

Constructor Details

This class inherits a constructor from Monga::Request

Instance Method Details

#bodyObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/monga/protocol/query.rb', line 14

def body
  @body ||= begin
    skip = @options[:skip] || 0
    limit = get_limit
    selector = @options[:selector] || {}

    query = {}
    query["$query"] = @options[:query] || {}
    query["$hint"] = @options[:hint] if @options[:hint]
    query["$orderby"] = @options[:sort] if @options[:sort]
    query["$explain"] = @options[:explain] if @options[:explain]

    msg = ::BinUtils.append_int32_le!(nil, flags)
    msg << full_name << Monga::NULL_BYTE
    ::BinUtils.append_int32_le!(msg, skip, limit)
    msg << query.to_bson
    msg << selector.to_bson if selector.any?
    msg
  end
end