diff --git a/lib/MongoDB/InsertManyResult.pm b/lib/MongoDB/InsertManyResult.pm index 0f87a7c6..64f325b3 100644 --- a/lib/MongoDB/InsertManyResult.pm +++ b/lib/MongoDB/InsertManyResult.pm @@ -44,11 +44,17 @@ The number of documents inserted. =cut has inserted_count => ( - is => 'ro', - default => 0, + is => 'lazy', + builder => '_build_inserted_count', isa => Num, ); +sub _build_inserted_count +{ + my ($self) = @_; + return scalar @{ $self->inserted }; +} + =attr inserted An array reference containing information about inserted documents (if any). diff --git a/t/crud.t b/t/crud.t index 40c04b0e..3a00c8f3 100644 --- a/t/crud.t +++ b/t/crud.t @@ -116,6 +116,7 @@ subtest "insert_many" => sub { }, "inserted_ids contains correct keys/values" ); + is($res->inserted_count, 2, "Two docs inserted."); # ordered insert should halt on error $coll->drop;