line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2014 - present MongoDB, Inc. |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
4
|
|
|
|
|
|
|
# you may not use this file except in compliance with the License. |
5
|
|
|
|
|
|
|
# You may obtain a copy of the License at |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software |
10
|
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
11
|
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12
|
|
|
|
|
|
|
# See the License for the specific language governing permissions and |
13
|
|
|
|
|
|
|
# limitations under the License. |
14
|
|
|
|
|
|
|
|
15
|
58
|
|
|
58
|
|
447
|
use strict; |
|
58
|
|
|
|
|
181
|
|
|
58
|
|
|
|
|
1808
|
|
16
|
58
|
|
|
58
|
|
317
|
use warnings; |
|
58
|
|
|
|
|
128
|
|
|
58
|
|
|
|
|
2174
|
|
17
|
|
|
|
|
|
|
package MongoDB::Op::_ListCollections; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Encapsulate collection list operations; returns arrayref of collection |
20
|
|
|
|
|
|
|
# names |
21
|
|
|
|
|
|
|
|
22
|
58
|
|
|
58
|
|
315
|
use version; |
|
58
|
|
|
|
|
122
|
|
|
58
|
|
|
|
|
395
|
|
23
|
|
|
|
|
|
|
our $VERSION = 'v2.2.0'; |
24
|
|
|
|
|
|
|
|
25
|
58
|
|
|
58
|
|
4413
|
use Moo; |
|
58
|
|
|
|
|
128
|
|
|
58
|
|
|
|
|
339
|
|
26
|
|
|
|
|
|
|
|
27
|
58
|
|
|
58
|
|
18151
|
use MongoDB::Op::_Command; |
|
58
|
|
|
|
|
159
|
|
|
58
|
|
|
|
|
1570
|
|
28
|
58
|
|
|
58
|
|
386
|
use MongoDB::Op::_Query; |
|
58
|
|
|
|
|
167
|
|
|
58
|
|
|
|
|
1679
|
|
29
|
58
|
|
|
58
|
|
373
|
use MongoDB::ReadConcern; |
|
58
|
|
|
|
|
175
|
|
|
58
|
|
|
|
|
1595
|
|
30
|
58
|
|
|
58
|
|
344
|
use MongoDB::ReadPreference; |
|
58
|
|
|
|
|
159
|
|
|
58
|
|
|
|
|
2062
|
|
31
|
58
|
|
|
|
|
487
|
use MongoDB::_Types qw( |
32
|
|
|
|
|
|
|
Document |
33
|
|
|
|
|
|
|
ReadPreference |
34
|
58
|
|
|
58
|
|
382
|
); |
|
58
|
|
|
|
|
277
|
|
35
|
58
|
|
|
|
|
430
|
use Types::Standard qw( |
36
|
|
|
|
|
|
|
HashRef |
37
|
|
|
|
|
|
|
InstanceOf |
38
|
|
|
|
|
|
|
Str |
39
|
58
|
|
|
58
|
|
40233
|
); |
|
58
|
|
|
|
|
139
|
|
40
|
58
|
|
|
58
|
|
55155
|
use Tie::IxHash; |
|
58
|
|
|
|
|
146
|
|
|
58
|
|
|
|
|
1276
|
|
41
|
58
|
|
|
58
|
|
301
|
use boolean; |
|
58
|
|
|
|
|
122
|
|
|
58
|
|
|
|
|
527
|
|
42
|
|
|
|
|
|
|
|
43
|
58
|
|
|
58
|
|
4547
|
use namespace::clean; |
|
58
|
|
|
|
|
138
|
|
|
58
|
|
|
|
|
365
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has client => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
required => 1, |
48
|
|
|
|
|
|
|
isa => InstanceOf['MongoDB::MongoClient'], |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has filter => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
required => 1, |
54
|
|
|
|
|
|
|
isa => Document, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has options => ( |
58
|
|
|
|
|
|
|
is => 'ro', |
59
|
|
|
|
|
|
|
required => 1, |
60
|
|
|
|
|
|
|
isa => HashRef, |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has read_preference => ( |
64
|
|
|
|
|
|
|
is => 'rw', # rw for Op::_Query which can be modified by Cursor |
65
|
|
|
|
|
|
|
required => 1, |
66
|
|
|
|
|
|
|
isa => ReadPreference, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
with $_ for qw( |
70
|
|
|
|
|
|
|
MongoDB::Role::_PrivateConstructor |
71
|
|
|
|
|
|
|
MongoDB::Role::_DatabaseOp |
72
|
|
|
|
|
|
|
MongoDB::Role::_CommandCursorOp |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub execute { |
76
|
0
|
|
|
0
|
0
|
|
my ( $self, $link, $topology ) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
my $res = |
79
|
|
|
|
|
|
|
$link->supports_list_commands |
80
|
|
|
|
|
|
|
? $self->_command_list_colls( $link, $topology ) |
81
|
|
|
|
|
|
|
: $self->_legacy_list_colls( $link, $topology ); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $res; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _command_list_colls { |
87
|
0
|
|
|
0
|
|
|
my ( $self, $link, $topology ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $options = $self->options; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# batchSize is not a command parameter itself like other options |
92
|
0
|
|
|
|
|
|
my $batchSize = delete $options->{batchSize}; |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
if ( defined $batchSize ) { |
95
|
0
|
|
|
|
|
|
$options->{cursor} = { batchSize => $batchSize }; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
0
|
|
|
|
|
|
$options->{cursor} = {}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Normalize or delete 'nameOnly' |
102
|
0
|
0
|
|
|
|
|
if ($options->{nameOnly}) { |
103
|
0
|
|
|
|
|
|
$options->{nameOnly} = true; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else { |
106
|
0
|
|
|
|
|
|
delete $options->{nameOnly}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $filter = |
110
|
|
|
|
|
|
|
ref( $self->filter ) eq 'ARRAY' |
111
|
0
|
0
|
|
|
|
|
? { @{ $self->filter } } |
|
0
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
: $self->filter; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $cmd = Tie::IxHash->new( |
115
|
|
|
|
|
|
|
listCollections => 1, |
116
|
|
|
|
|
|
|
filter => $filter, |
117
|
|
|
|
|
|
|
nameOnly => false, |
118
|
0
|
|
|
|
|
|
%{$self->options}, |
|
0
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $op = MongoDB::Op::_Command->_new( |
122
|
|
|
|
|
|
|
db_name => $self->db_name, |
123
|
|
|
|
|
|
|
query => $cmd, |
124
|
|
|
|
|
|
|
query_flags => {}, |
125
|
|
|
|
|
|
|
bson_codec => $self->bson_codec, |
126
|
|
|
|
|
|
|
session => $self->session, |
127
|
|
|
|
|
|
|
monitoring_callback => $self->monitoring_callback, |
128
|
|
|
|
|
|
|
read_preference => $self->read_preference, |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $res = $op->execute( $link, $topology ); |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return $self->_build_result_from_cursor( $res ); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _legacy_list_colls { |
137
|
0
|
|
|
0
|
|
|
my ( $self, $link, $topology ) = @_; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
0
|
|
|
|
my $op = MongoDB::Op::_Query->_new( |
140
|
|
|
|
|
|
|
filter => $self->filter, |
141
|
|
|
|
|
|
|
options => MongoDB::Op::_Query->precondition_options($self->options), |
142
|
|
|
|
|
|
|
db_name => $self->db_name, |
143
|
|
|
|
|
|
|
coll_name => 'system.namespaces', |
144
|
|
|
|
|
|
|
full_name => $self->db_name . ".system.namespaces", |
145
|
|
|
|
|
|
|
bson_codec => $self->bson_codec, |
146
|
|
|
|
|
|
|
client => $self->client, |
147
|
|
|
|
|
|
|
read_preference => $self->read_preference || MongoDB::ReadPreference->new, |
148
|
|
|
|
|
|
|
read_concern => MongoDB::ReadConcern->new, |
149
|
|
|
|
|
|
|
post_filter => \&__filter_legacy_names, |
150
|
|
|
|
|
|
|
monitoring_callback => $self->monitoring_callback, |
151
|
|
|
|
|
|
|
); |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
return $op->execute( $link, $topology ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# exclude names with '$' except oplog.$ |
157
|
|
|
|
|
|
|
# XXX why do we include oplog.$? |
158
|
|
|
|
|
|
|
sub __filter_legacy_names { |
159
|
0
|
|
|
0
|
|
|
my $doc = shift; |
160
|
|
|
|
|
|
|
# remove leading database name for compatibility with listCollections |
161
|
0
|
|
|
|
|
|
$doc->{name} =~ s/^[^.]+\.//; |
162
|
0
|
|
|
|
|
|
my $name = $doc->{name}; |
163
|
0
|
|
0
|
|
|
|
return !( index( $name, '$' ) >= 0 && index( $name, '.oplog.$' ) < 0 ); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |