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
2 changes: 1 addition & 1 deletion lib/MongoDB/Collection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ sub __ixhash {
if ( $type eq 'HASH' ) {
$hash->{$key} = Tie::IxHash->new( %$ref );
}
elsif ( $type eq 'ARRAY' ) {
elsif ( $type eq 'ARRAY' || $type eq 'BSON::Doc' ) {
$hash->{$key} = Tie::IxHash->new( @$ref );
}
else {
Expand Down
43 changes: 43 additions & 0 deletions t/collection.t
Original file line number Diff line number Diff line change
Expand Up @@ -1016,4 +1016,47 @@ for my $criteria ( $js_str, $js_obj ) {
};
}

subtest "sort standard hash" => sub {

$coll->drop;

$coll->insert_many( [
{ _id => 1, size => 10 },
{ _id => 2, size => 5 },
{ _id => 3, size => 15 },
] );

my @res = $coll->find( {}, { sort => { size => 1 } } )->result->all;

cmp_deeply \@res,
[
{ _id => 2, size => 5 },
{ _id => 1, size => 10 },
{ _id => 3, size => 15 },
],
'Got correct sort order';
};

subtest "sort BSON::Doc" => sub {

$coll->drop;

$coll->insert_many( [
{ _id => 1, size => 10 },
{ _id => 2, size => 5 },
{ _id => 3, size => 15 },
] );

my $b_doc = bson_doc( size => 1 );
my @res = $coll->find( {}, { sort => $b_doc } )->result->all;

cmp_deeply \@res,
[
{ _id => 2, size => 5 },
{ _id => 1, size => 10 },
{ _id => 3, size => 15 },
],
'Got correct sort order';
};

done_testing;