微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

文档对象属性上的MongoDbOdm SearchFilter

如何解决文档对象属性上的MongoDbOdm SearchFilter

我目前在过滤对象属性方面遇到问题,这应该很简单。

这是我的一个mongodb文档(位置)的示例

{
"_id" : ObjectId("5f734d5dd8de1284db20348d"),"id" : 181,"name" : "Base Esperanza","name_additional" : "ARG","type" : "city","type_description" : null,"loc" : {
    "type" : "Point","coordinates" : [ 
        -56.983333,-63.4
    ]
},"altitude" : 60,"inhabitants" : 0,"timezone_name" : "UTC","priority" : 123,"indexable" : 200,"location_id_parent" : null,"continent" : {
    "name" : "Antarktis"
},"country" : {
    "name" : "Antarktis","iso_code" : "AQ"
},"province" : {
    "name" : null
},"district" : {
    "name" : null
}

}

我想执行一个查询,以将所有值为“ AQ”的文档返回为country.iso_code

这是我的位置信息类:

<?PHP

namespace App\Document;

use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\SearchFilter;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Field;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;

/**
 * @ApiResource(
 *     collectionoperations={"get"={"method"="GET"}},*     itemOperations={"get"={"method"="GET"}}
 * )
 * @ApiFilter(SearchFilter::class,properties={"name": "exact","country.iso_code": "exact"})
 *
 * @Document
 */
class Location
{
    /**
     * @Id
     */
    private $id;

    /**
     * @Field(type="string")
     */
    public $name;

    /**
     * @Field(type="string")
     */
    public $type;

    /**
     * @Field(type="string")
     */
    public $type_description;

    /**
     * @Field(type="int")
     */
    public $priority;

    /**
     * @Field(type="collection")
     */
    public $continent;

    /**
     * @Field(type="collection")
     */
    public $country;

    /**
     * @Field(type="collection")
     */
    public $province;

    /**
     * @Field(type="collection")
     */
    public $district;

    /**
     * @return string
     */
    public function getId(): string
    {
        return $this->id;
    }
}

我已经定义了一个指向country.iso_code的SearchFilter 不幸的是,以下查询返回所有文档,而不是过滤结果集。

https:// localhost:8443 / locations?country.iso_code = AQ

对不是对象的其他属性(例如“名称”)进行过滤。

我对属性“国家”的mongodb文档是否定义了不利?应该是一个包含对象的数组吗?

作为集合的属性定义是否错误

我很高兴您的支持。非常感谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。