---
name: "Mango::Bulk"
section: "3pm"
platform: "linux"
package: "libmango-perl"
version: "1.30-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Mango::Bulk"
---

# Mango::Bulk(3pm)

MongoDB bulk operations

## NAME

Mango::Bulk - MongoDB bulk operations

## SYNOPSIS

```
  use Mango::Bulk;
  my $bulk = Mango::Bulk->new(collection => $collection);
  $bulk->insert({foo => 'bar'})->insert({foo => 'baz'})->execute;
```

## DESCRIPTION

Mango::Bulk is a container for MongoDB bulk operations, all operations will be automatically grouped so they don't exceed "max\_bson\_size" in Mango.

## ATTRIBUTES

Mango::Bulk implements the following attributes.

### collection

```
  my $collection = $bulk->collection;
  $bulk          = $bulk->collection(Mango::Collection->new);
```

Mango::Collection object this bulk operation belongs to.

### ordered

```
  my $bool = $bulk->ordered;
  $bulk    = $bulk->ordered($bool);
```

Bulk operations are ordered, defaults to a true value.

## METHODS

Mango::Bulk inherits all methods from Mojo::Base and implements the following new ones.

### execute

```
  my $results = $bulk->execute;
```

Execute bulk operations. You can also append a callback to perform operation non-blocking.

```
  $bulk->execute(sub {
    my ($bulk, $err, $results) = @_;
    ...
  });
  Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
```

### find

```
  $bulk = $bulk->find({foo => 'bar'});
```

Query for next update or remove operation.

### insert

```
  $bulk = $bulk->insert({foo => 'bar'});
```

Insert document.

### remove

```
  $bulk = $bulk->remove;
```

Remove multiple documents.

### remove\_one

```
  $bulk = $bulk->remove_one;
```

Remove one document.

### update

```
  $bulk = $bulk->update({foo => 'bar'});
```

Update multiple documents.

### update\_one

```
  $bulk = $bulk->update_one({foo => 'baz'});
```

Update one document.

### upsert

```
  $bulk = $bulk->upsert;
```

Next update operation will be an `"upsert"`.

## SEE ALSO

Mango, Mojolicious::Guides, \<http://mojolicio.us\>.
