---
name: "MongoDB::BulkWriteResult"
section: "3pm"
platform: "linux"
package: "libmongodb-perl"
version: "2.2.2-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/MongoDB::BulkWriteResult"
---

# MongoDB::BulkWriteResult(3pm)

MongoDB bulk write result document

## NAME

MongoDB::BulkWriteResult - MongoDB bulk write result document

## VERSION

version v2.2.2

## SYNOPSIS

```
    # returned directly
    my $result = $bulk->execute;
    # from a WriteError or WriteConcernError
    my $result = $error->result;
    if ( $result->acknowledged ) {
        ...
    }
```

## DESCRIPTION

This class encapsulates the results from a bulk write operation. It may be returned directly from `"execute"` or it may be in the `"result"` attribute of a `"MongoDB::DatabaseError"` subclass like `"MongoDB::WriteError"` or `"MongoDB::WriteConcernError"`.

## ATTRIBUTES

### inserted\_count

Number of documents inserted

### upserted\_count

Number of documents upserted

### matched\_count

Number of documents matched for an update or replace operation.

### deleted\_count

Number of documents removed

### modified\_count

Number of documents actually modified by an update operation. This is not necessarily the same as "matched\_count" if the document was not actually modified as a result of the update.

This field is not available from legacy servers before version 2.6. If results are seen from a legacy server (or from a mongos proxying for a legacy server) this attribute will be `"undef"`.

You can call `"has_modified_count"` to find out if this attribute is defined or not.

### upserted

An array reference containing information about upserted documents (if any). Each document will have the following fields:

- •

  index — 0-based index indicating which operation failed

- •

  \_id — the object ID of the upserted document

### upserted\_ids

A hash reference built lazily from `"upserted"` mapping indexes to object IDs.

### inserted

An array reference containing information about inserted documents (if any). Documents are just as in `"upserted"`.

### inserted\_ids

A hash reference built lazily from `"inserted"` mapping indexes to object IDs.

### write\_errors

An array reference containing write errors (if any).  Each error document will have the following fields:

- •

  index — 0-based index indicating which operation failed

- •

  code — numeric error code

- •

  errmsg — textual error string

- •

  op — a representation of the actual operation sent to the server

### write\_concern\_errors

An array reference containing write concern errors (if any).  Each error document will have the following fields:

- •

  index — 0-based index indicating which operation failed

- •

  code — numeric error code

### op\_count

The number of operations sent to the database.

### batch\_count

The number of database commands issued to the server.  This will be less than the `"op_count"` if multiple operations were grouped together.

## METHODS

### assert

Throws an error if write errors or write concern errors occurred.

### assert\_no\_write\_error

Throws a MongoDB::WriteError if `"count_write_errors"` is non-zero; otherwise returns 1.

### assert\_no\_write\_concern\_error

Throws a MongoDB::WriteConcernError if `"count_write_concern_errors"` is non-zero; otherwise returns 1.

### count\_write\_errors

Returns the number of write errors

### count\_write\_concern\_errors

Returns the number of write errors

### last\_code

Returns the last `"code"` field from either the list of `"write_errors"` or `"write_concern_errors"` or 0 if there are no errors.

### last\_errmsg

Returns the last `"errmsg"` field from either the list of `"write_errors"` or `"write_concern_errors"` or the empty string if there are no errors.

### last\_wtimeout

True if a write concern timed out or false otherwise.

## AUTHORS

- •

  David Golden \<david@mongodb.com\>

- •

  Rassi \<rassi@mongodb.com\>

- •

  Mike Friedman \<friedo@friedo.com\>

- •

  Kristina Chodorow \<k.chodorow@gmail.com\>

- •

  Florian Ragwitz \<rafl@debian.org\>

## COPYRIGHT AND LICENSE

This software is Copyright (c) 2020 by MongoDB, Inc.

This is free software, licensed under:

```
  The Apache License, Version 2.0, January 2004
```
