Skip to content

Instantly share code, notes, and snippets.

@exodist
Last active August 29, 2015 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exodist/ef08a3c406d98c1bb618 to your computer and use it in GitHub Desktop.
Save exodist/ef08a3c406d98c1bb618 to your computer and use it in GitHub Desktop.
smallest mongo+test-simple script
use strict;
use warnings;
use Test::More 'no_plan';
use MongoDB::Timestamp; # needed if db is being run as master
use MongoDB;
use lib "t/lib";
use MongoDBTest qw/build_client get_test_db/;
my $conn = build_client();
my $testdb = get_test_db($conn);
$testdb->drop;
my $dbname = $testdb->name;
my $coll = $conn->ns("$dbname.test_collection");
$coll->ensure_index({"x.y" => 1}, {"name" => "foo"});
ok(1);
my ($index) = grep { $_->{name} eq 'foo' } $coll->get_indexes;
ok(1);
__END__
Ways to make the problem go away:
ok(1);
my ($index) = grep { $_->{name} eq 'foo' } $coll->get_indexes;
$index = undef
ok(1);
ok(1);
{
my ($index) = grep { $_->{name} eq 'foo' } $coll->get_indexes;
}
ok(1);
ok(1);
grep { $_->{name} eq 'foo' } $coll->get_indexes;
ok(1);
@dolmen
Copy link

dolmen commented May 1, 2015

As the MongoDB module is involved, could you post the $VERSION or the commit of MongoDB?

@jberger
Copy link

jberger commented May 2, 2015

What about a temporary array to hold the result of $coll->get_indexes? Will that also make the problem go away?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment