# Poco::MongoDB

# class InsertRequest

Library: MongoDB
Package: MongoDB
Header: Poco/MongoDB/InsertRequest.h

## Description

A request for inserting one or more documents to the database (OP_INSERT).

## Inheritance

Direct Base Classes: RequestMessage

All Base Classes: Message, RequestMessage

## Member Summary

Member Functions: addNewDocument, buildRequest, documents

Inherited Functions: buildRequest, header, messageLength, send

## Enumerations

### Flags

INSERT_DEFAULT = 0

If specified, perform a normal insert operation.

INSERT_CONTINUE_ON_ERROR = 1

If set, the database will not stop processing a bulk insert if one fails (e.g. due to duplicate IDs). This makes bulk insert behave similarly to a series of single inserts, except lastError will be set if any insert fails, not just the last one. If multiple errors occur, only the most recent will be reported.

## Constructors

### InsertRequest

InsertRequest(
const std::string & collectionName,
Flags flags = INSERT_DEFAULT
);

Creates an InsertRequest.

The full collection name is the concatenation of the database name with the collection name, using a "." for the concatenation. For example, for the database "foo" and the collection "bar", the full collection name is "foo.bar".

## Destructor

### ~InsertRequest

virtual ~InsertRequest();

Destroys the InsertRequest.

## Member Functions

### addNewDocument

Document & addNewDocument();

Adds a new document for insertion. A reference to the empty document is returned. InsertRequest is the owner of the Document and will free it on destruction.

### documents

Document::Vector & documents();

Returns the documents to insert into the database.

### buildRequest

void buildRequest(
BinaryWriter & writer
);

See also: Poco::MongoDB::RequestMessage::buildRequest()