···
has 'collection' => ( is => 'ro', isa => 'MongoDB::Collection' );
has 'db_name' => ( is => 'ro', isa => 'Str', default => 'chi' );
has 'safe' => ( is => 'rw', isa => 'Bool', default => 0 );
18
-
has 'use_oid' => ( is => 'rw', isa => 'Bool', default => 0 );
__PACKAGE__->meta->make_immutable();
···
40
-
( $self->{use_oid} )
41
-
? MongoDB::OID->new( value => unpack( "H*", $key ) )
my $results = $self->collection->find_one( { _id => $key }, { data => 1 } );
return ($results) ? $results->{data} : undef;
···
my ( $self, $key, $data ) = @_;
51
-
( $self->{use_oid} )
52
-
? MongoDB::OID->new( value => unpack( "H*", $key ) )
$self->collection->save( { _id => $key, data => $data },
{ safe => $self->{safe} } );
···
63
-
( $self->{use_oid} )
64
-
? MongoDB::OID->new( value => unpack( "H*", $key ) )
$self->collection->remove( { _id => $key }, { safe => $self->{safe} } );
···
77
-
return ( !shift->{use_oid} )
78
-
? map { $_->{_id} } shift->collection->find( {}, { _id => 1 } )->all
79
-
: croak 'Cannot get keys when converting keys to OID';
64
+
map { $_->{_id} } shift->collection->find( {}, { _id => 1 } )->all;
···
Optional flag to confirm insertion/removal. This will slow down writes significantly.
146
-
Optional flag to convert key to OID. This speeds up gets, slows retrieval, and removes the ability to get_keys.