RUBY-283 add_option for cursors. Deprecate Cursor#query_opts.
This commit is contained in:
parent
5950f6850f
commit
237dc98fbf
@ -1,5 +1,10 @@
|
|||||||
# MongoDB Ruby Driver History
|
# MongoDB Ruby Driver History
|
||||||
|
|
||||||
|
### 1.4.0
|
||||||
|
UNRELEASED
|
||||||
|
|
||||||
|
* Add Cursor#add_option. Deprecate Cursor#query_opts and replace with Cursor#options.
|
||||||
|
|
||||||
### 1.3.1
|
### 1.3.1
|
||||||
2011-5-10
|
2011-5-10
|
||||||
|
|
||||||
|
@ -20,10 +20,12 @@ module Mongo
|
|||||||
class Cursor
|
class Cursor
|
||||||
include Mongo::Conversions
|
include Mongo::Conversions
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
include Mongo::Constants
|
||||||
|
|
||||||
attr_reader :collection, :selector, :fields,
|
attr_reader :collection, :selector, :fields,
|
||||||
:order, :hint, :snapshot, :timeout,
|
:order, :hint, :snapshot, :timeout,
|
||||||
:full_collection_name, :transformer
|
:full_collection_name, :transformer,
|
||||||
|
:options
|
||||||
|
|
||||||
# Create a new cursor.
|
# Create a new cursor.
|
||||||
#
|
#
|
||||||
@ -59,6 +61,7 @@ module Mongo
|
|||||||
@limit = opts[:limit] || 0
|
@limit = opts[:limit] || 0
|
||||||
@tailable = opts[:tailable] || false
|
@tailable = opts[:tailable] || false
|
||||||
@timeout = opts.fetch(:timeout, true)
|
@timeout = opts.fetch(:timeout, true)
|
||||||
|
@options = 0
|
||||||
|
|
||||||
# Use this socket for the query
|
# Use this socket for the query
|
||||||
@socket = opts[:socket]
|
@socket = opts[:socket]
|
||||||
@ -73,6 +76,16 @@ module Mongo
|
|||||||
@cache = []
|
@cache = []
|
||||||
@returned = 0
|
@returned = 0
|
||||||
|
|
||||||
|
if(!@timeout)
|
||||||
|
add_option(OP_QUERY_NO_CURSOR_TIMEOUT)
|
||||||
|
end
|
||||||
|
if(@connection.slave_ok?)
|
||||||
|
add_option(OP_QUERY_SLAVE_OK)
|
||||||
|
end
|
||||||
|
if(@tailable)
|
||||||
|
add_option(OP_QUERY_TAILABLE)
|
||||||
|
end
|
||||||
|
|
||||||
if @collection.name =~ /^\$cmd/ || @collection.name =~ /^system/
|
if @collection.name =~ /^\$cmd/ || @collection.name =~ /^system/
|
||||||
@command = true
|
@command = true
|
||||||
else
|
else
|
||||||
@ -274,7 +287,8 @@ module Mongo
|
|||||||
#
|
#
|
||||||
# @core explain explain-instance_method
|
# @core explain explain-instance_method
|
||||||
def explain
|
def explain
|
||||||
c = Cursor.new(@collection, query_options_hash.merge(:limit => -@limit.abs, :explain => true))
|
c = Cursor.new(@collection,
|
||||||
|
query_options_hash.merge(:limit => -@limit.abs, :explain => true))
|
||||||
explanation = c.next_document
|
explanation = c.next_document
|
||||||
c.close
|
c.close
|
||||||
|
|
||||||
@ -315,11 +329,21 @@ module Mongo
|
|||||||
# @see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-Mongo::Constants::OPQUERY
|
# @see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-Mongo::Constants::OPQUERY
|
||||||
# The MongoDB wire protocol.
|
# The MongoDB wire protocol.
|
||||||
def query_opts
|
def query_opts
|
||||||
opts = 0
|
warn "The method Cursor#query_opts has been deprecated " +
|
||||||
opts |= Mongo::Constants::OP_QUERY_NO_CURSOR_TIMEOUT unless @timeout
|
"and will removed in v2.0. Use Cursor#options instead."
|
||||||
opts |= Mongo::Constants::OP_QUERY_SLAVE_OK if @connection.slave_ok?
|
@options
|
||||||
opts |= Mongo::Constants::OP_QUERY_TAILABLE if @tailable
|
end
|
||||||
opts
|
|
||||||
|
# Add an option to the query options bitfield.
|
||||||
|
#
|
||||||
|
# @param opt a valid query option
|
||||||
|
#
|
||||||
|
# @return [Integer] the current value of options for this cursor.
|
||||||
|
#
|
||||||
|
# @see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-Mongo::Constants::OPQUERY
|
||||||
|
def add_option(opt)
|
||||||
|
@options |= opt
|
||||||
|
return @options
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the query options for this Cursor.
|
# Get the query options for this Cursor.
|
||||||
@ -418,7 +442,7 @@ module Mongo
|
|||||||
|
|
||||||
def construct_query_message
|
def construct_query_message
|
||||||
message = BSON::ByteBuffer.new
|
message = BSON::ByteBuffer.new
|
||||||
message.put_int(query_opts)
|
message.put_int(@options)
|
||||||
BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}")
|
BSON::BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@collection.name}")
|
||||||
message.put_int(@skip)
|
message.put_int(@skip)
|
||||||
message.put_int(@limit)
|
message.put_int(@limit)
|
||||||
|
@ -2,8 +2,8 @@ require './test/test_helper'
|
|||||||
require 'logger'
|
require 'logger'
|
||||||
|
|
||||||
class CursorTest < Test::Unit::TestCase
|
class CursorTest < Test::Unit::TestCase
|
||||||
|
|
||||||
include Mongo
|
include Mongo
|
||||||
|
include Mongo::Constants
|
||||||
|
|
||||||
@@connection = standard_connection
|
@@connection = standard_connection
|
||||||
@@db = @@connection.db(MONGO_TEST_DB)
|
@@db = @@connection.db(MONGO_TEST_DB)
|
||||||
@ -16,6 +16,12 @@ class CursorTest < Test::Unit::TestCase
|
|||||||
@@coll_full_name = "#{MONGO_TEST_DB}.test"
|
@@coll_full_name = "#{MONGO_TEST_DB}.test"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_add_options
|
||||||
|
c = @@coll.find
|
||||||
|
c.add_option(OP_QUERY_EXHAUST)
|
||||||
|
assert c.options & OP_QUERY_EXHAUST
|
||||||
|
end
|
||||||
|
|
||||||
def test_inspect
|
def test_inspect
|
||||||
selector = {:a => 1}
|
selector = {:a => 1}
|
||||||
cursor = @@coll.find(selector)
|
cursor = @@coll.find(selector)
|
||||||
|
Loading…
Reference in New Issue
Block a user