Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
6 changes: 6 additions & 0 deletions devel/config/mongod-4.0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
type: single
default_args: -v --bind_ip 0.0.0.0 --enableMajorityReadConcern
default_version: 4.0
mongod:
- name: host1
16 changes: 13 additions & 3 deletions lib/MongoDB/Op/_Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use MongoDB::_Constants;
use MongoDB::_Types qw(
Document
ReadPreference
to_IxHash
);
use List::Util qw/first/;
use Types::Standard qw(
Expand Down Expand Up @@ -87,9 +88,18 @@ sub execute {
# $query is passed as a reference because it *may* be replaced
$self->_apply_read_prefs( $link, $topology_type, $self->{query_flags}, \$self->{query});

my ( $op_bson, $request_id ) =
MongoDB::_Protocol::write_query( $self->{db_name} . '.$cmd',
$self->{bson_codec}->encode_one( $self->{query} ), undef, 0, -1, $self->{query_flags});
my ( $op_bson, $request_id );

if ( $link->supports_op_msg ) {
$self->{query} = to_IxHash( $self->{query} );
$self->{query}->Push( '$db', $self->db_name );
( $op_bson, $request_id ) =
MongoDB::_Protocol::write_msg( $self->{bson_codec}, undef, $self->{query} );
} else {
( $op_bson, $request_id ) =
MongoDB::_Protocol::write_query( $self->{db_name} . '.$cmd',
$self->{bson_codec}->encode_one( $self->{query} ), undef, 0, -1, $self->{query_flags});
}

if ( length($op_bson) > MAX_BSON_WIRE_SIZE ) {
# XXX should this become public?
Expand Down
20 changes: 14 additions & 6 deletions lib/MongoDB/Role/_SingleBatchDocWrite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use MongoDB::_Constants;
use MongoDB::_Protocol;
use MongoDB::_Types qw(
WriteConcern
to_IxHash
);

use namespace::clean;
Expand Down Expand Up @@ -167,12 +168,19 @@ sub _send_write_command {

$self->_apply_session_and_cluster_time( $link, \$cmd );

# send command and get response document
my $command = $self->bson_codec->encode_one( $cmd );

my ( $op_bson, $request_id ) =
MongoDB::_Protocol::write_query( $self->db_name . '.$cmd',
$command, undef, 0, -1, undef );
my ( $op_bson, $request_id );
if ( $link->supports_op_msg ) {
$cmd = to_IxHash( $cmd );
$cmd->Push( '$db', $self->db_name );
( $op_bson, $request_id ) =
MongoDB::_Protocol::write_msg( $self->bson_codec, undef, $cmd );
} else {
# send command and get response document
my $command = $self->bson_codec->encode_one( $cmd );
( $op_bson, $request_id ) =
MongoDB::_Protocol::write_query( $self->db_name . '.$cmd',
$command, undef, 0, -1, undef );
}

if ( length($op_bson) > MAX_BSON_WIRE_SIZE ) {
# XXX should this become public?
Expand Down
8 changes: 8 additions & 0 deletions lib/MongoDB/_Link.pm
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ has supports_retryWrites => (
isa => Boolish,
);

has supports_op_msg => (
is => 'rwp',
init_arg => undef,
isa => Boolish,
);

# for wire version >= 7
has supports_4_0_changestreams => (
is => 'rwp',
init_arg => undef,
Expand Down Expand Up @@ -355,6 +362,7 @@ sub set_metadata {
? 1
: 0
);
$self->_set_supports_op_msg(1);
}
if ( $self->accepts_wire_version(7) ) {
$self->_set_supports_4_0_changestreams(1);
Expand Down
Loading