Use an aggregation pipeline.
Convert the objects embedded in selling_types to an array
$convertSellingTypesToArray = [
'$project' => [
'finance.selling_types' => [
'$objectToArray' => '$finance.selling_types'
]
]
];
Then unwind the array to individual documents
$sellingTypesAsDocuments = [
'$unwind' => '$finance.selling_types'
];
Filter where status is 1.
$selectOnlyActiveStatus = [
'$match' => [
'finance.selling_types.v.status' => [
'$eq' => 1
]
]
];
Convert selling_types back as an object.
$convertSellingTypesToObject = [
'$project' => [
'finance.selling_types' => [
'$arrayToObject' => [
[
'$finance.selling_types'
],
]
]
]
];
finances::raw()->aggregate([
$convertSellingTypesToArray,
$sellingTypesAsDocuments,
$selectOnlyActiveStatus,
$convertSellingTypesToObject,
])
Note that you'll need to support pagination on the query
*or$$inside where conditionDB::collection('finances')->where('finance.sellingTypes.status',1)->get()