MongoCollectionAdapter
in package
implements
MongoCollectionInterface
Thin adapter that wraps `\MongoDB\Collection` and makes it satisfy `MongoCollectionInterface`.
The real \MongoDB\Collection returns UpdateResult / DeleteResult
from mutation methods. This adapter discards those return values so the
interface can declare void, keeping MongoStorage independent of the
mongodb/mongodb userland library at the interface level.
findOneAndUpdate is forwarded with returnDocument: RETURN_DOCUMENT_AFTER
so that the result reflects the document state after the update — required
for MongoStorage's empty-document cleanup logic.
Table of Contents
Interfaces
- MongoCollectionInterface
- Minimal collection interface required by `MongoStorage`.
Properties
- $collection : Collection
Methods
- __construct() : mixed
- Wrap a `\MongoDB\Collection` and apply a typeMap that deep-converts nested BSON documents to plain PHP arrays on read-back.
- deleteOne() : void
- Delete a single document matching `$filter`.
- findOne() : null|object
- Find a single document matching `$filter`.
- findOneAndUpdate() : null|object
- Atomically find a document, apply `$update`, and return the result.
- updateOne() : void
- Update a single document matching `$filter`.
Properties
$collection read-only
private
Collection
$collection
Methods
__construct()
Wrap a `\MongoDB\Collection` and apply a typeMap that deep-converts nested BSON documents to plain PHP arrays on read-back.
public
__construct(Collection $collection) : mixed
Without a typeMap findOne returns a BSONDocument for the top-level
document and nested embedded documents stay as BSONDocument instances.
A shallow (array)$document->data cast inside MongoStorage::getData
would then leave nested values as BSONDocument rather than arrays,
violating the array<string, mixed> storage contract.
TypeMap:
'root' => 'object'— keeps the top-level findOne result as?object(matches theMongoCollectionInterface::findOnereturn-type signature).'document' => 'array'— nested BSON embedded documents become PHP arrays.'array' => 'array'— BSON arrays become PHP arrays.
Applies via Collection::withOptions so the original $collection is
unchanged (the caller may reuse it with different options).
Parameters
- $collection : Collection
deleteOne()
Delete a single document matching `$filter`.
public
deleteOne(array<string, mixed> $filter[, array<string, mixed> $options = [] ]) : void
Parameters
- $filter : array<string, mixed>
- $options : array<string, mixed> = []
findOne()
Find a single document matching `$filter`.
public
findOne(array<string, mixed> $filter[, array<string, mixed> $options = [] ]) : null|object
Parameters
- $filter : array<string, mixed>
- $options : array<string, mixed> = []
Return values
null|object —Matched document, or null when no document matches.
findOneAndUpdate()
Atomically find a document, apply `$update`, and return the result.
public
findOneAndUpdate(array<string, mixed> $filter, array<string, mixed> $update[, array<string, mixed> $options = [] ]) : null|object
Parameters
- $filter : array<string, mixed>
- $update : array<string, mixed>
- $options : array<string, mixed> = []
Return values
null|object —Document after update, or null when no document matches.
updateOne()
Update a single document matching `$filter`.
public
updateOne(array<string, mixed> $filter, array<string, mixed> $update[, array<string, mixed> $options = [] ]) : void
Parameters
- $filter : array<string, mixed>
- $update : array<string, mixed>
- $options : array<string, mixed> = []