lib/mongo/database/view.rb in mongo-2.5.3 vs lib/mongo/database/view.rb in mongo-2.6.0

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (C) 2014-2017 MongoDB, Inc. +# Copyright (C) 2014-2018 MongoDB, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # @@ -33,11 +33,11 @@ attr_reader :limit # @return [ Collection ] collection The command collection. attr_reader :collection - # Get all the names of the non system collections in the database. + # Get all the names of the non-system collections in the database. # # @example Get the collection names. # database.collection_names # # @param [ Hash ] options Options for the listCollections command. @@ -51,11 +51,11 @@ def collection_names(options = {}) @batch_size = options[:batch_size] server = next_primary(false) @limit = -1 if server.features.list_collections_enabled? session = client.send(:get_session, options) - collections_info(server, session).collect do |info| + collections_info(server, session, name_only: true).collect do |info| if server.features.list_collections_enabled? info[Database::NAME] else (info[Database::NAME] && info[Database::NAME].sub("#{@database.name}.", '')) @@ -91,32 +91,32 @@ @collection = @database[Database::COMMAND] end private - def collections_info(server, session, &block) - cursor = Cursor.new(self, send_initial_query(server, session), server, session: session) + def collections_info(server, session, options = {}, &block) + cursor = Cursor.new(self, send_initial_query(server, session, options), server, session: session) cursor.each do |doc| yield doc end if block_given? cursor.to_enum end - def collections_info_spec(session) + def collections_info_spec(session, options = {}) { selector: { listCollections: 1, cursor: batch_size ? { batchSize: batch_size } : {} }, db_name: @database.name, session: session - } + }.tap { |spec| spec[:selector][:nameOnly] = true if options[:name_only] } end - def initial_query_op(session) - Operation::CollectionsInfo.new(collections_info_spec(session)) + def initial_query_op(session, options = {}) + Operation::CollectionsInfo.new(collections_info_spec(session, options)) end - def send_initial_query(server, session) - initial_query_op(session).execute(server) + def send_initial_query(server, session, options = {}) + initial_query_op(session, options).execute(server) end end end end