简体   繁体   中英

How to use MongoDb specific operator $size to find array size greater than, less than, between and not equal to a value in Laravel / jenssegers?

I am working on a Laravel dynamic where clause eloquent model. I want to find the collection with the size of an array field having size values greater than, less than, between and not equal to.

I am using jenssegers and in the jenssegers documentation, the code to find documents with array size to a specific value is given, but I need to use it to find <,>,!= and between .

User::where('tags', 'size', 3)->get();

I can't use aggregate and $where since I am using a dynamic where clause to find the desired result.

Finally, I fixed the issue myself. The answer is:

$query->whereRaw(['$where' => 'this.tags.length > 1'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM