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
|
|
421
|
use strict; |
|
58
|
|
|
|
|
142
|
|
|
58
|
|
|
|
|
1639
|
|
16
|
58
|
|
|
58
|
|
319
|
use warnings; |
|
58
|
|
|
|
|
129
|
|
|
58
|
|
|
|
|
2643
|
|
17
|
|
|
|
|
|
|
package MongoDB::BulkWriteView; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ABSTRACT: Bulk write operations against a query document |
20
|
|
|
|
|
|
|
|
21
|
58
|
|
|
58
|
|
343
|
use version; |
|
58
|
|
|
|
|
173
|
|
|
58
|
|
|
|
|
314
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.0'; |
23
|
|
|
|
|
|
|
|
24
|
58
|
|
|
58
|
|
4266
|
use Moo; |
|
58
|
|
|
|
|
197
|
|
|
58
|
|
|
|
|
397
|
|
25
|
|
|
|
|
|
|
|
26
|
58
|
|
|
58
|
|
20137
|
use MongoDB::Error; |
|
58
|
|
|
|
|
172
|
|
|
58
|
|
|
|
|
6204
|
|
27
|
58
|
|
|
|
|
531
|
use MongoDB::_Types qw( |
28
|
|
|
|
|
|
|
Boolish |
29
|
|
|
|
|
|
|
Document |
30
|
|
|
|
|
|
|
IxHash |
31
|
58
|
|
|
58
|
|
454
|
); |
|
58
|
|
|
|
|
145
|
|
32
|
58
|
|
|
|
|
433
|
use Types::Standard qw( |
33
|
|
|
|
|
|
|
Maybe |
34
|
|
|
|
|
|
|
ArrayRef |
35
|
|
|
|
|
|
|
InstanceOf |
36
|
58
|
|
|
58
|
|
80766
|
); |
|
58
|
|
|
|
|
147
|
|
37
|
58
|
|
|
58
|
|
54867
|
use boolean; |
|
58
|
|
|
|
|
147
|
|
|
58
|
|
|
|
|
469
|
|
38
|
58
|
|
|
58
|
|
4305
|
use namespace::clean -except => 'meta'; |
|
58
|
|
|
|
|
145
|
|
|
58
|
|
|
|
|
477
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# A hash reference containing a MongoDB query document |
41
|
|
|
|
|
|
|
has _query => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => IxHash, |
44
|
|
|
|
|
|
|
coerce => IxHash->coercion, |
45
|
|
|
|
|
|
|
required => 1 |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Originating bulk write object for executing write operations. |
49
|
|
|
|
|
|
|
has _bulk => ( |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
isa => InstanceOf['MongoDB::BulkWrite'], |
52
|
|
|
|
|
|
|
required => 1, |
53
|
|
|
|
|
|
|
handles => [qw/_enqueue_write/] |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has _collation => ( |
57
|
|
|
|
|
|
|
is => 'ro', |
58
|
|
|
|
|
|
|
isa => Maybe [Document], |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has _array_filters => ( |
62
|
|
|
|
|
|
|
is => 'ro', |
63
|
|
|
|
|
|
|
isa => Maybe [ArrayRef[Document]], |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has _upsert => ( |
67
|
|
|
|
|
|
|
is => 'ro', |
68
|
|
|
|
|
|
|
isa => Boolish, |
69
|
|
|
|
|
|
|
default => 0, |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub collation { |
73
|
0
|
|
|
0
|
1
|
|
my ($self, $collation) = @_; |
74
|
0
|
|
|
|
|
|
return $self->new( %$self, _collation => $collation ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub arrayFilters { |
78
|
0
|
|
|
0
|
1
|
|
my ( $self, $array_filters ) = @_; |
79
|
0
|
|
|
|
|
|
return $self->new( %$self, _array_filters => $array_filters ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub upsert { |
83
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
84
|
0
|
0
|
|
|
|
|
unless ( @_ == 1 ) { |
85
|
0
|
|
|
|
|
|
MongoDB::UsageError->throw("the upsert method takes no arguments"); |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
return $self->new( %$self, _upsert => true ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub update_many { |
91
|
0
|
|
|
0
|
1
|
|
push @_, "update_many"; |
92
|
0
|
|
|
|
|
|
goto &_update; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub update_one { |
96
|
0
|
|
|
0
|
1
|
|
push @_, "update_one"; |
97
|
0
|
|
|
|
|
|
goto &_update; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub replace_one { |
101
|
0
|
|
|
0
|
1
|
|
push @_, "replace_one"; |
102
|
0
|
|
|
|
|
|
goto &_update; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _update { |
106
|
0
|
|
|
0
|
|
|
my $method = pop @_; |
107
|
0
|
|
|
|
|
|
my ( $self, $doc ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my $type = ref $doc; |
110
|
0
|
0
|
0
|
|
|
|
unless ( @_ == 2 && grep { $type eq $_ } qw/HASH ARRAY Tie::IxHash/ ) { |
|
0
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
MongoDB::UsageError->throw("argument to $method must be a single hashref, arrayref or Tie::IxHash"); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
if ( ref $doc eq 'ARRAY' ) { |
|
|
0
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
MongoDB::UsageError->throw("array reference to $method must have key/value pairs") |
116
|
|
|
|
|
|
|
if @$doc % 2; |
117
|
0
|
|
|
|
|
|
$doc = Tie::IxHash->new(@$doc); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
elsif ( ref $doc eq 'HASH' ) { |
120
|
0
|
|
|
|
|
|
$doc = Tie::IxHash->new(%$doc); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
|
$self->_bulk->_retryable( 0 ) if $method eq 'update_many'; |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
my $update = { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
126
|
|
|
|
|
|
|
q => $self->_query, |
127
|
|
|
|
|
|
|
u => $doc, |
128
|
|
|
|
|
|
|
multi => $method eq 'update_many' ? true : false, |
129
|
|
|
|
|
|
|
upsert => boolean( $self->_upsert ), |
130
|
|
|
|
|
|
|
is_replace => $method eq 'replace_one', |
131
|
|
|
|
|
|
|
(defined $self->_collation ? (collation => $self->_collation) : ()), |
132
|
|
|
|
|
|
|
(defined $self->_array_filters ? (arrayFilters => $self->_array_filters) : ()), |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$self->_enqueue_write( [ update => $update ] ); |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub delete_many { |
141
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
142
|
0
|
|
|
|
|
|
$self->_bulk->_retryable( 0 ); |
143
|
0
|
0
|
|
|
|
|
$self->_enqueue_write( |
|
|
0
|
|
|
|
|
|
144
|
|
|
|
|
|
|
[ |
145
|
|
|
|
|
|
|
delete => { |
146
|
|
|
|
|
|
|
q => $self->_query, |
147
|
|
|
|
|
|
|
limit => 0, |
148
|
|
|
|
|
|
|
( defined $self->_collation ? ( collation => $self->_collation ) : () ), |
149
|
|
|
|
|
|
|
(defined $self->_array_filters ? (arrayFilters => $self->_array_filters) : ()), |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
] |
152
|
|
|
|
|
|
|
); |
153
|
0
|
|
|
|
|
|
return; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub delete_one { |
157
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
158
|
0
|
0
|
|
|
|
|
$self->_enqueue_write( |
|
|
0
|
|
|
|
|
|
159
|
|
|
|
|
|
|
[ |
160
|
|
|
|
|
|
|
delete => { |
161
|
|
|
|
|
|
|
q => $self->_query, |
162
|
|
|
|
|
|
|
limit => 1, |
163
|
|
|
|
|
|
|
( defined $self->_collation ? ( collation => $self->_collation ) : () ), |
164
|
|
|
|
|
|
|
(defined $self->_array_filters ? (arrayFilters => $self->_array_filters) : ()), |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
] |
167
|
|
|
|
|
|
|
); |
168
|
0
|
|
|
|
|
|
return; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |