diff --git a/lib/mongo/client.rb b/lib/mongo/client.rb index 3c0fcb4543..326451fa4d 100644 --- a/lib/mongo/client.rb +++ b/lib/mongo/client.rb @@ -36,8 +36,8 @@ class Client # @return [ Hash ] options The configuration options. attr_reader :options - # Delegate command execution to the current database. - def_delegators :@database, :command + # Delegate command and collections execution to the current database. + def_delegators :@database, :command, :collections # Delegate subscription to monitoring. def_delegators :@monitoring, :subscribe, :unsubscribe diff --git a/spec/mongo/client_spec.rb b/spec/mongo/client_spec.rb index 405af9e464..05b496f97d 100644 --- a/spec/mongo/client_spec.rb +++ b/spec/mongo/client_spec.rb @@ -742,4 +742,24 @@ expect(client.dup.options).to be_a(Mongo::Options::Redacted) end end + + describe '#collections' do + + before do + authorized_client.database[:users].create + end + + after do + authorized_client.database[:users].drop + end + + let(:collection) do + Mongo::Collection.new(authorized_client.database, 'users') + end + + it 'refers the current database collections' do + expect(authorized_client.collections).to include(collection) + expect(authorized_client.collections).to all(be_a(Mongo::Collection)) + end + end end