File tree Expand file tree Collapse file tree 5 files changed +60
-9
lines changed Expand file tree Collapse file tree 5 files changed +60
-9
lines changed Original file line number Diff line number Diff line change @@ -232,20 +232,18 @@ def write_concern
232
232
#
233
233
# @since 2.0.5
234
234
def database_names
235
- use ( Database ::ADMIN ) . command (
236
- listDatabases : 1
237
- ) . first [ 'databases' ] . collect { |info | info [ 'name' ] }
235
+ list_databases . collect { |info | info [ 'name' ] }
238
236
end
239
237
240
238
# Get info for each database.
241
239
#
242
- # @example Get the database info.
243
- # client.database_info
240
+ # @example Get the info for each database .
241
+ # client.list_databases
244
242
#
245
- # @return [ Array<Hash ] The info for each database.
243
+ # @return [ Array<Hash> ] The info for each database.
246
244
#
247
245
# @since 2.0.5
248
- def database_info
246
+ def list_databases
249
247
use ( Database ::ADMIN ) . command (
250
248
listDatabases : 1
251
249
) . first [ 'databases' ]
Original file line number Diff line number Diff line change @@ -102,6 +102,18 @@ def collection_names(options = {})
102
102
View . new ( self ) . collection_names ( options )
103
103
end
104
104
105
+ # Get info on all the collections in the database.
106
+ #
107
+ # @example Get info on each collection.
108
+ # database.list_collections
109
+ #
110
+ # @return [ Array<Hash> ] Info for each collection in the database.
111
+ #
112
+ # @since 2.0.5
113
+ def list_collections
114
+ View . new ( self ) . list_collections
115
+ end
116
+
105
117
# Get all the collections that belong to this database.
106
118
#
107
119
# @example Get all the collections.
Original file line number Diff line number Diff line change @@ -57,6 +57,18 @@ def collection_names(options = {})
57
57
end
58
58
end
59
59
60
+ # Get info on all the collections in the database.
61
+ #
62
+ # @example Get info on each collection.
63
+ # database.list_collections
64
+ #
65
+ # @return [ Array<Hash> ] Info for each collection in the database.
66
+ #
67
+ # @since 2.0.5
68
+ def list_collections
69
+ collections_info ( next_primary )
70
+ end
71
+
60
72
# Create the new database view.
61
73
#
62
74
# @example Create the new database view.
Original file line number Diff line number Diff line change 579
579
end
580
580
end
581
581
582
- describe '#database_info ' do
582
+ describe '#list_databases ' do
583
583
584
584
it 'returns a list of database info documents' do
585
585
expect (
586
- root_authorized_client . database_info . collect do |i |
586
+ root_authorized_client . list_databases . collect do |i |
587
587
i [ 'name' ]
588
588
end ) . to include ( 'admin' , 'local' , TEST_DB )
589
589
end
Original file line number Diff line number Diff line change 95
95
end
96
96
end
97
97
98
+ describe '#list_collections' do
99
+
100
+ let ( :database ) do
101
+ described_class . new ( authorized_client , TEST_DB )
102
+ end
103
+
104
+ let ( :result ) do
105
+ database . list_collections . map do |info |
106
+ info [ 'name' ]
107
+ end
108
+ end
109
+
110
+ before do
111
+ database [ :users ] . create
112
+ end
113
+
114
+ after do
115
+ database [ :users ] . drop
116
+ end
117
+
118
+ it 'returns a list of the collections info' , if : write_command_enabled? do
119
+ expect ( result ) . to include ( 'users' )
120
+ end
121
+
122
+ it 'returns a list of the collections info' , unless : write_command_enabled? do
123
+ expect ( result ) . to include ( "#{ TEST_DB } .users" )
124
+ end
125
+ end
126
+
98
127
describe '#collections' do
99
128
100
129
context 'when the database exists' do
You can’t perform that action at this time.
0 commit comments