/usr/lib/x86_64-linux-gnu/perl5/5.26/MongoDB/Op/_Aggregate.pm is in libmongodb-perl 1.8.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | #
# Copyright 2015 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
use strict;
use warnings;
package MongoDB::Op::_Aggregate;
# Encapsulate aggregate operation; return MongoDB::QueryResult
use version;
our $VERSION = 'v1.8.1';
use Moo;
use MongoDB::Op::_Command;
use MongoDB::_Types qw(
ArrayOfHashRef
);
use Types::Standard qw(
Bool
HashRef
InstanceOf
);
use namespace::clean;
has client => (
is => 'ro',
required => 1,
isa => InstanceOf ['MongoDB::MongoClient'],
);
has pipeline => (
is => 'ro',
required => 1,
isa => ArrayOfHashRef,
);
has options => (
is => 'ro',
required => 1,
isa => HashRef,
);
has has_out => (
is => 'ro',
required => 1,
isa => Bool,
);
with $_ for qw(
MongoDB::Role::_PrivateConstructor
MongoDB::Role::_CollectionOp
MongoDB::Role::_ReadOp
MongoDB::Role::_WriteOp
MongoDB::Role::_CommandCursorOp
);
sub execute {
my ( $self, $link, $topology ) = @_;
my $options = $self->options;
my $is_2_6 = $link->does_write_commands;
# maxTimeMS isn't available until 2.6 and the aggregate command
# will reject it as unrecognized
delete $options->{maxTimeMS} unless $is_2_6;
# bypassDocumentValidation isn't available until 3.2 (wire version 4)
delete $options->{bypassDocumentValidation} unless $link->accepts_wire_version(4);
if ( defined $options->{collation} and !$link->supports_collation ) {
MongoDB::UsageError->throw(
"MongoDB host '" . $link->address . "' doesn't support collation" );
}
# If 'cursor' is explicitly false, we disable using cursors, even
# for MongoDB 2.6+. This allows users operating with a 2.6+ mongos
# and pre-2.6 mongod in shards to avoid fatal errors. This
# workaround should be removed once MongoDB 2.4 is no longer supported.
my $use_cursor = $is_2_6
&& ( !exists( $options->{cursor} ) || $options->{cursor} );
# batchSize is not a command parameter itself like other options
my $batchSize = delete $options->{batchSize};
# If we're doing cursors, we first respect an explicit batchSize option;
# next we fallback to the legacy (deprecated) cursor option batchSize; finally we
# just give an empty document. Other than batchSize we ignore any other
# legacy cursor options. If we're not doing cursors, don't send any
# cursor option at all, as servers will choke on it.
if ($use_cursor) {
if ( defined $batchSize ) {
$options->{cursor} = { batchSize => $batchSize };
}
elsif ( ref $options->{cursor} eq 'HASH' ) {
$batchSize = $options->{cursor}{batchSize};
$options->{cursor} = defined($batchSize) ? { batchSize => $batchSize } : {};
}
else {
$options->{cursor} = {};
}
}
else {
delete $options->{cursor};
}
my $has_out = $self->has_out;
my @command = (
aggregate => $self->coll_name,
pipeline => $self->pipeline,
%$options,
(
!$has_out && $link->accepts_wire_version(4) ? @{ $self->read_concern->as_args } : ()
),
(
$has_out && $link->accepts_wire_version(5) ? @{ $self->write_concern->as_args } : ()
),
);
my $op = MongoDB::Op::_Command->_new(
db_name => $self->db_name,
query => Tie::IxHash->new(@command),
query_flags => {},
bson_codec => $self->bson_codec,
( $has_out ? () : ( read_preference => $self->read_preference ) ),
);
my $res = $op->execute( $link, $topology );
$res->assert_no_write_concern_error if $has_out;
# For explain, we give the whole response as fields have changed in
# different server versions
if ( $options->{explain} ) {
return MongoDB::QueryResult->_new(
_client => $self->client,
_address => $link->address,
_full_name => '',
_bson_codec => $self->bson_codec,
_batch_size => 1,
_cursor_at => 0,
_limit => 0,
_cursor_id => 0,
_cursor_start => 0,
_cursor_flags => {},
_cursor_num => 1,
_docs => [ $res->output ],
);
}
# Fake up a single-batch cursor if we didn't get a cursor response.
# We use the 'results' fields as the first (and only) batch
if ( !$res->output->{cursor} ) {
$res->output->{cursor} = {
ns => '',
id => 0,
firstBatch => ( delete $res->output->{result} ) || [],
};
}
return $self->_build_result_from_cursor($res);
}
1;
|