I have this table that has a field I called videos
and the type of that field is array
. Now I want to get all the records that have at least 1 value inside videos field
. Below is my code that doesn't return what I want.
$prod = Product::where(array('videos' => array('$ne' => 0)))->get();
I am using laravel 4.2 and mongoDb as my database.
May be this answer could help you as I came up with the solution that Json
encodes the data in array. So when it's empty the value will be []
. So you can query it something like this
$prod = Product::where('videos', '!=', '[]')->get();
I am glad that I found the solution to this. It needs to know that field videos
exists and not empty. Take a look at below code:
$prod = Product::where(array('videos' => array('$ne' => [], '$exists' => true)))->get();
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.