AnyMongo
view release on metacpan or search on metacpan
t/perl-driver-api/collection.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Test::Exception;
use Data::Dumper;
use Data::Types qw(:float);
use Tie::IxHash;
use Encode qw(encode decode);
use AnyMongo::Compat;
my $conn;
eval {
my $host = "localhost";
if (exists $ENV{MONGOD}) {
$host = $ENV{MONGOD};
}
$conn = MongoDB::Connection->new(host => $host);
};
if ($@) {
plan skip_all => $@;
}
else {
plan tests => 118;
}
my $db = $conn->get_database('test_database');
$db->drop;
my $coll = $db->get_collection('test_collection');
isa_ok($coll, 'MongoDB::Collection');
is($coll->name, 'test_collection', 'get name');
$db->drop;
# very small insert
my $id = $coll->insert({_id => 1});
is($id, 1);
my $tiny = $coll->find_one;
is($tiny->{'_id'}, 1);
$coll->remove;
$id = $coll->insert({});
isa_ok($id, 'MongoDB::OID');
$tiny = $coll->find_one;
is($tiny->{'_id'}, $id);
$coll->remove;
# insert
$id = $coll->insert({ just => 'another', perl => 'hacker' });
is($coll->count, 1, 'count');
$coll->update({ _id => $id }, {
just => "an\xE4oth\0er",
mongo => 'hacker',
with => { a => 'reference' },
and => [qw/an array reference/],
});
is($coll->count, 1);
is($coll->count({ mongo => 'programmer' }), 0, 'count = 0');
( run in 1.115 second using v1.01-cache-2.11-cpan-39bf76dae61 )