File tree Expand file tree Collapse file tree 9 files changed +76
-29
lines changed Expand file tree Collapse file tree 9 files changed +76
-29
lines changed Original file line number Diff line number Diff line change @@ -458,7 +458,7 @@ part of the command:
458
458
459
459
.. code-block:: ruby
460
460
461
- client.database.command(collstats: 'test' , readConcern: {level: :majority})
461
+ client.database.command(dbStats: 1 , readConcern: {level: :majority})
462
462
463
463
464
464
.. _read-preference:
@@ -504,7 +504,7 @@ option when a command is run on a database:
504
504
} )
505
505
506
506
# Set read preference for a given command
507
- client.database.command( { collstats: 'test' }, read: { mode: secondary,
507
+ client.database.command( { dbStats: 1 }, read: { mode: secondary,
508
508
tag_sets: [ { 'dc' => 'nyc' } ] } )
509
509
510
510
Read preference can also be set for specific operations on a collection
Original file line number Diff line number Diff line change @@ -314,7 +314,9 @@ def with(new_options)
314
314
#
315
315
# @since 2.0.0
316
316
def capped?
317
- database . read_command ( :collstats => name ) . documents [ 0 ] [ CAPPED ]
317
+ database . list_collections ( filter : { name : name } )
318
+ . first
319
+ &.dig ( 'options' , CAPPED ) || false
318
320
end
319
321
320
322
# Force the collection to be created in the database.
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ module SessionsSupported
30
30
31
31
READ_COMMANDS = [
32
32
:aggregate ,
33
- :collStats ,
34
33
:count ,
35
34
:dbStats ,
36
35
:distinct ,
Original file line number Diff line number Diff line change 162
162
163
163
# Start runCommand Example 2
164
164
165
- client . database . command ( collStats : 'restaurants' )
165
+ client . database . command ( dbStats : 1 )
166
166
167
167
# End runCommand Example 2
168
168
end
Original file line number Diff line number Diff line change 137
137
end
138
138
139
139
let ( :collstats ) do
140
- database . read_command ( :collstats => :specs ) . documents . first
140
+ collection . aggregate ( [ { '$collStats' => { 'storageStats' => { } } } ] ) . first
141
+ end
142
+
143
+ let ( :storage_stats ) do
144
+ collstats . fetch ( 'storageStats' , { } )
141
145
end
142
146
143
147
let ( :options ) do
157
161
end
158
162
159
163
it "applies the options" do
160
- expect ( collstats [ "capped" ] ) . to be true
161
- expect ( collstats [ "max" ] ) . to eq ( 512 )
162
- expect ( collstats [ "maxSize" ] ) . to eq ( 4096 )
164
+ expect ( storage_stats [ "capped" ] ) . to be true
165
+ expect ( storage_stats [ "max" ] ) . to eq ( 512 )
166
+ expect ( storage_stats [ "maxSize" ] ) . to eq ( 4096 )
163
167
end
164
168
end
165
169
end
Original file line number Diff line number Diff line change 651
651
end
652
652
653
653
let ( :collstats ) do
654
- database . read_command ( :collstats => :specs ) . documents . first
654
+ collection . aggregate ( [ { '$collStats' => { 'storageStats' => { } } } ] ) . first
655
+ end
656
+
657
+ let ( :storage_stats ) do
658
+ collstats . fetch ( 'storageStats' , { } )
655
659
end
656
660
657
661
before do
664
668
end
665
669
666
670
it "applies the options" do
667
- expect ( collstats [ "capped" ] ) . to be true
668
- expect ( collstats [ "max" ] ) . to eq ( 512 )
669
- expect ( collstats [ "maxSize" ] ) . to eq ( 4096 )
671
+ expect ( storage_stats [ "capped" ] ) . to be true
672
+ expect ( storage_stats [ "max" ] ) . to eq ( 512 )
673
+ expect ( storage_stats [ "maxSize" ] ) . to eq ( 4096 )
670
674
end
671
675
end
672
676
Original file line number Diff line number Diff line change @@ -320,22 +320,22 @@ def set_initial_data
320
320
collection = root_authorized_client . with ( write_concern : { w : :majority } ) .
321
321
use ( spec . use! ( 'databaseName' ) ) [ spec . use! ( 'collectionName' ) ]
322
322
collection . drop
323
+ create_options = spec . use ( 'createOptions' ) || { }
323
324
docs = spec . use! ( 'documents' )
324
- if docs . any?
325
- collection . insert_many ( docs )
326
- else
327
- begin
328
- collection . create
329
- rescue Mongo ::Error => e
330
- if Mongo ::Error ::OperationFailure === e && (
325
+ begin
326
+ collection . create ( create_options )
327
+ rescue Mongo ::Error => e
328
+ if Mongo ::Error ::OperationFailure === e && (
331
329
e . code == 48 || e . message =~ /collection already exists/
332
- )
333
- # Already exists
334
- else
335
- raise
336
- end
330
+ )
331
+ # Already exists
332
+ else
333
+ raise
337
334
end
338
335
end
336
+ if docs . any?
337
+ collection . insert_many ( docs )
338
+ end
339
339
unless spec . empty?
340
340
raise NotImplementedError , "Unhandled spec keys: #{ spec } "
341
341
end
Original file line number Diff line number Diff line change @@ -26,17 +26,18 @@ tests:
26
26
command :
27
27
ping : 1
28
28
command_name : ping
29
- - description : " current op is not bypassed"
29
+ - description : " kill op is not bypassed"
30
30
clientOptions :
31
31
autoEncryptOpts :
32
32
kmsProviders :
33
33
aws : {} # Credentials filled in from environment.
34
34
operations :
35
35
- name : runCommand
36
36
object : database
37
- command_name : currentOp
37
+ command_name : killOp
38
38
arguments :
39
39
command :
40
- currentOp : 1
40
+ killOp : 1
41
+ op : 1234
41
42
result :
42
- errorContains : " command not supported for auto encryption: currentOp "
43
+ errorContains : " command not supported for auto encryption: killOp "
Original file line number Diff line number Diff line change
1
+ description : collectionData-createOptions
2
+ schemaVersion : " 1.9"
3
+ runOnRequirements :
4
+ - minServerVersion : " 3.6"
5
+ # Capped collections cannot be created on serverless instances.
6
+ serverless : forbid
7
+ createEntities :
8
+ - client :
9
+ id : &client0 client0
10
+ - database :
11
+ id : &database0 database0
12
+ client : *client0
13
+ databaseName : &database0Name database0
14
+ - collection :
15
+ id : &collection0 collection0
16
+ database : *database0
17
+ collectionName : &collection0Name coll0
18
+ initialData :
19
+ - collectionName : *collection0Name
20
+ databaseName : *database0Name
21
+ createOptions :
22
+ capped : true
23
+ # With MMAPv1, the size field cannot be less than 4096.
24
+ size : &cappedSize 4096
25
+ documents :
26
+ - { _id: 1, x: 11 }
27
+ tests :
28
+ - description : collection is created with the correct options
29
+ operations :
30
+ - object : *collection0
31
+ name : aggregate
32
+ arguments :
33
+ pipeline :
34
+ - $collStats : { storageStats: {} }
35
+ - $project : { capped: '$storageStats.capped', maxSize: '$storageStats.maxSize'}
36
+ expectResult :
37
+ - { capped: true, maxSize: *cappedSize }
You can’t perform that action at this time.
0 commit comments