Skip to content

BulkWrite operations fails on references with extra fields #159

Closed
@alcaeus

Description

@alcaeus

This was previously reported in alcaeus/mongo-php-adapter#101. Doing a BulkWrite update with certain documents causes the following warning: mongoc: WARNING > mongoc_bulk_operation_replace_one(): replacement document may not contain $ or . in keys. Ignoring document..

Looking into the error I've found that this occurs when doing a bulk write containing a reference that has an extra field before $ref:

$filter = ['x' => 11];
$replacement = ['test' => ['type' => 'test', '$ref' => 'collection', '$id' => 2]];

$operation = new ReplaceOne($this->getDatabaseName(), $this->getCollectionName(), $filter, $replacement);

This error does not occur when passing the extra field in the DBRef document at the end, e.g. ['$ref' => 'collection', '$id' => 2, 'type' => 'test'].

On the other hand, doing the very same thing in an update operation does not cause this error, the update goes through just fine. I'll be adding a pull request containing three tests for the scenarios: replace with an extra field after the reference, replace with an extra field before the reference and an update with an extra field before the reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions