Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/MongoDB/Collection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,10 @@ sub bulk_write {
}
}

return $bulk->execute( undef, { session => $session } );
return $bulk->execute(
$options->{writeConcern},
{ session => $session },
);
}

BEGIN {
Expand Down
2 changes: 1 addition & 1 deletion lib/MongoDB/QueryResult.pm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ has _cursor_num => (
isa => Num,
);

sub _inc_cursor_num { $_[0]{_cursor_num}++ }
sub _inc_cursor_num { $_[0]{_cursor_num} += $_[1] }

has _docs => (
is => 'ro',
Expand Down
7 changes: 6 additions & 1 deletion lib/MongoDB/Role/_CommandCursorOp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ sub _build_result_from_cursor {
$max_time_ms = $self->maxAwaitTimeMS if $self->maxAwaitTimeMS;
}

my $limit = 0;
if ($self->isa('MongoDB::Op::_Query')) {
$limit = $self->limit if $self->limit;
}

my $batch = $c->{firstBatch};
my $qr = MongoDB::QueryResult->_new(
_client => $self->client,
Expand All @@ -58,7 +63,7 @@ sub _build_result_from_cursor {
_bson_codec => $self->bson_codec,
_batch_size => scalar @$batch,
_cursor_at => 0,
_limit => 0,
_limit => $limit,
_cursor_id => $c->{id},
_cursor_start => 0,
_cursor_flags => {},
Expand Down
14 changes: 14 additions & 0 deletions t/collection.t
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,20 @@ subtest "querying w/ collation" => sub {
}
};

subtest "bulk_write writeConcern used" => sub {
plan skip_all => "Test requires ReplicaSet"
unless $server_type eq 'RSPrimary';

$coll->drop;

like exception {
$coll->bulk_write(
[insert_one => [{ x => 3 }]],
{ writeConcern => { w => 999 } },
);
}, qr/WriteConcernError/, 'write concern is taken into account';
};

my $js_str = 'function() { return this.a > this.b }';
my $js_obj = MongoDB::Code->new( code => $js_str );

Expand Down
7 changes: 7 additions & 0 deletions t/cursor.t
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ my @values;
is ($values[2]->{foo}, 4);
}

# limit propagation to result
{
my $c = $coll->query({}, { limit => 3, sort_by => { foo => 1 } });
is($c->result->_limit, 3, 'query limit was propagated');
}

# skip
{
@values = $coll->query({}, { limit => 3, skip => 1, sort_by => { foo => 1 } })->all;
Expand Down Expand Up @@ -305,6 +311,7 @@ $coll->drop;
$cursor->all;
$info = $cursor->info;
is($info->{at}, 1000);
is($info->{num}, 1000, 'cursor_num after ->all');
}

# sort_by
Expand Down