I'm using Symfony and Mongo. I have documents for each of my mongo collections. In the documents I defined all fields to be strings, even though some of them typically contain numerical values.
I perform searches in these collections and filter them like this:
private function like($paramValue) {
return new \MongoRegex("/.*" . FilterHelper::castValue(FilterType::INT, $paramValue) . ".*/ix");
}
...
$qb->field('articleId')->equals( $this->like($params['articleCode']) );
However, values are persisted as numbers in mongo, "article_id": NumberInt(197568)
. The document is written like this:
/**
* @MongoDB\String(name="article_id")
*/
protected $articleId;
Naturally, queries fail because the type is not the expected. How can I fix this? I can't assume $articleId
is a number.