Skip to content

MongoDB ODM SearchFilter expects DbRef usage on associations, when documentation and lookup code requires raw id #2574

@andytson

Description

@andytson

The code of the MongoDb ODM SearchFilter expects the association field to be stored as a DbRef, when the documentation states raw ids should be used, and lookups can't use DbRef.
https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilter.php#L138

Issue present in api-platform/core v2.4.0-beta.2

Steps to reproduce:

  • Create a MongoDB BlogPost Document class, and annotate @ApiFilter(Searchfilter::class, properties={"author": "exact"} and add annotations for a reference 'author' to another document Author class with storeAs="id"
  • Debug the $aggregationBuilder->getPipeline() in SearchFilter
  • Make a call to /blogpost/?author=1

Expected pipeline:

[{"$match":{"author":{"$in":[1]}}}]

Actual pipeline

[{"$match":{"author.$id":{"$in":[1]}}}]

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