lib/mongo/database/view.rb in mongo-2.18.3 vs lib/mongo/database/view.rb in mongo-2.19.0
- old
+ new
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-# encoding: utf-8
+# rubocop:todo all
# Copyright (C) 2014-2020 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -102,10 +102,13 @@
# required privilege to run the command when access control is enforced
#
# See https://mongodb.com/docs/manual/reference/command/listCollections/
# for more information and usage.
# @option options [ Session ] :session The session to use.
+ # @option options [ Boolean ] :deserialize_as_bson Whether to deserialize
+ # this message using BSON types instead of native Ruby types wherever
+ # possible.
#
# @return [ Array<Hash> ] Info for each collection in the database.
#
# @since 2.0.5
def list_collections(options = {})
@@ -139,11 +142,11 @@
# ])
#
# @param [ Array<Hash> ] pipeline The aggregation pipeline.
# @param [ Hash ] options The aggregation options.
#
- # @return [ Aggregation ] The aggregation object.
+ # @return [ Collection::View::Aggregation ] The aggregation object.
#
# @since 2.10.0
# @api private
def aggregate(pipeline, options = {})
Collection::View::Aggregation.new(self, pipeline, options)
@@ -170,11 +173,11 @@
if description.server_version_gte?('3.0')
cursor.reject do |doc|
doc['name'].start_with?('system.') || doc['name'].include?('$')
end
else
- docs = cursor.reject do |doc|
+ cursor.reject do |doc|
doc['name'].start_with?("#{database.name}.system") || doc['name'].include?('$')
end
end
end
@@ -194,11 +197,45 @@
def initial_query_op(session, options = {})
Operation::CollectionsInfo.new(collections_info_spec(session, options))
end
+ # Sends command that obtains information about the database.
+ #
+ # This command returns a cursor, so there could be additional commands,
+ # therefore this method is called send *initial* command.
+ #
+ # @param [ Server ] server Server to send the query to.
+ # @param [ Session ] session Session that should be used to send the query.
+ # @param [ Hash ] options
+ # @option options [ Hash | nil ] :filter A query expression to filter
+ # the list of collections.
+ # @option options [ true | false | nil ] :name_only A flag to indicate
+ # whether the command should return just the collection/view names
+ # and type or return both the name and other information.
+ # @option options [ true | false | nil ] :authorized_collections A flag,
+ # when set to true and used with name_only: true, that allows a user
+ # without the required privilege (i.e. listCollections
+ # action on the database) to run the command when access control
+ # is enforced.
+ # @option options [ Object | nil ] :comment A user-provided comment to attach
+ # to this command.
+ # @option options [ true | false | nil ] :deserialize_as_bson Whether the
+ # query results should be deserialized to BSON types, or to Ruby
+ # types (where possible).
+ #
+ # @return [ Operation::Result ] Result of the query.
def send_initial_query(server, session, options = {})
- initial_query_op(session, options).execute(server, context: Operation::Context.new(client: client, session: session))
+ opts = options.dup
+ execution_opts = {}
+ if opts.key?(:deserialize_as_bson)
+ execution_opts[:deserialize_as_bson] = opts.delete(:deserialize_as_bson)
+ end
+ initial_query_op(session, opts).execute(
+ server,
+ context: Operation::Context.new(client: client, session: session),
+ options: execution_opts
+ )
end
end
end
end