lib/mongo/database/view.rb in mongo-2.4.3 vs lib/mongo/database/view.rb in mongo-2.5.0.beta
- old
+ new
@@ -20,11 +20,11 @@
# @since 2.0.0
class View
extend Forwardable
include Enumerable
- def_delegators :@database, :cluster, :read_preference
+ def_delegators :@database, :cluster, :read_preference, :client
def_delegators :cluster, :next_primary
# @return [ Integer ] batch_size The size of the batch of results
# when sending the listCollections command.
attr_reader :batch_size
@@ -50,11 +50,12 @@
# @since 2.0.0
def collection_names(options = {})
@batch_size = options[:batch_size]
server = next_primary(false)
@limit = -1 if server.features.list_collections_enabled?
- collections_info(server).collect do |info|
+ session = client.send(:get_session, options)
+ collections_info(server, session).collect do |info|
if server.features.list_collections_enabled?
info[Database::NAME]
else
(info[Database::NAME] &&
info[Database::NAME].sub("#{@database.name}.", ''))
@@ -69,11 +70,12 @@
#
# @return [ Array<Hash> ] Info for each collection in the database.
#
# @since 2.0.5
def list_collections
- collections_info(next_primary(false))
+ session = client.send(:get_session)
+ collections_info(next_primary(false), session)
end
# Create the new database view.
#
# @example Create the new database view.
@@ -89,30 +91,32 @@
@collection = @database[Database::COMMAND]
end
private
- def collections_info(server, &block)
- cursor = Cursor.new(self, send_initial_query(server), server).to_enum
+ def collections_info(server, session, &block)
+ cursor = Cursor.new(self, send_initial_query(server, session), server, session: session)
cursor.each do |doc|
yield doc
end if block_given?
- cursor
+ cursor.to_enum
end
- def collections_info_spec
+ def collections_info_spec(session)
{ selector: {
listCollections: 1,
cursor: batch_size ? { batchSize: batch_size } : {} },
- db_name: @database.name }
+ db_name: @database.name,
+ session: session
+ }
end
- def initial_query_op
- Operation::Commands::CollectionsInfo.new(collections_info_spec)
+ def initial_query_op(session)
+ Operation::Commands::CollectionsInfo.new(collections_info_spec(session))
end
- def send_initial_query(server)
- initial_query_op.execute(server)
+ def send_initial_query(server, session)
+ initial_query_op(session).execute(server)
end
end
end
end