Result class for a single-document insert operation.
- Full name:
\MongoDB\InsertOneResult
private \MongoDB\Driver\WriteResult $writeResult
private mixed $insertedId
private bool $isAcknowledged
public __construct(\MongoDB\Driver\WriteResult $writeResult, mixed $insertedId): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$writeResult |
\MongoDB\Driver\WriteResult | |
$insertedId |
mixed |
Return the number of documents that were inserted.
public getInsertedCount(): int
This method should only be called if the write was acknowledged.
See Also:
- \MongoDB\InsertOneResult::isAcknowledged() -
Return the inserted document's ID.
public getInsertedId(): mixed
If the document had an ID prior to inserting (i.e. the driver did not need to generate an ID), this will contain its "_id". Any driver-generated ID will be a MongoDB\BSON\ObjectId instance.
Return whether this insert was acknowledged by the server.
public isAcknowledged(): bool
If the insert was not acknowledged, other fields from the WriteResult (e.g. insertedCount) will be undefined.
If the insert was not acknowledged, other fields from the WriteResult (e.g. insertedCount) will be undefined and their getter methods should not be invoked.