-
Hello, I wrote such a request using laravel ORM. If you insert this request directly into mongodb, then the request is correct, but in laravel it gives an error: $where is not allowed in this context There my ORM Request:
Exception:
|
Beta Was this translation helpful? Give feedback.
Answered by
GromNaN
Sep 25, 2023
Replies: 1 comment 8 replies
-
I just tried the provided request and didn't get any error. I used on version 4.0.0-rc1, what is your version? Alternatively you should use use MongoDB\BSON\Regex;
Item::query()->select('account_id', 'item_id', 'offer_id', 'fbo_sku', 'fbs_sku', 'barcodes')
->orWhere('item_id', new Regex(preg_quote($searchable), 'i'))
->orWhere('name', new Regex(preg_quote($searchable), 'i'))
->orWhere('fbo_sku', new Regex('^'.preg_quote($searchable), ''))
->orWhere('fbs_sku', new Regex('^'.preg_quote($searchable), ''))
->get(); |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to create a raw aggregation and group by this fields. The type of this fields doesn't matter.
https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/#behavior
With Laravel-mongodb, use the Model::raw()->aggregate() method.