How can we retrieve the size of an array in the laravel-mongodb's get()
function?
Update: Ultimately, I want to get the size of the array column for each qualified document
Example, for each document, I have an array of members data. Therefore, I would like to know for each document, how many members are there.
From Laravel's perspective, I could just load the entire member list for all qualified records and use count()
to get the array size in blade template. But I wanna avoid that because it will cause loading issue if the member list for each record is huge.
You can do
Model::where(column, condition)->count();
if Model extendsJenssegers\Mongodb\Eloquent\Model
Or
DB::collection(collectionName)->where(column, condition)->count();
You can find out more here: https://github.com/jenssegers/laravel-mongodb#readme