我在MongoDB中有两个集合,我想在它们之间进行聚合,效果很好,但是我不知道如何在其他集合中的级别的刀片(视图)中打印值?
$allRanges = Range::raw(( function($collection) {
return $collection->aggregate([
[
'$lookup' => [
'from' => 'Levels',
'localField' => 'LevelId',
'foreignField'=> '_id',
'as' => 'levels'
]
], [
'$match' =>[
'PlanTypeId'=> '5daad2c12939b70f0b7ff052'
]
],
]);
})))->toarray();
输出:
=> [
[
"_id" => "5daad809095e6f0c7e37fbf2",
"PlanTypeId" => "5daad2c12939b70f0b7ff052",
"LevelId" => "5dab14832d31e850ea1644b2",
"Range" => "range1",
"step" => 1,
"part" => 10,
"levels" => MongoDB\Model\BSONArray {#3149
flag::STD_PROP_LIST: false,
flag::ARRAY_AS_PROPS: false,
iteratorClass: "ArrayIterator",
storage: [
MongoDB\Model\BSONDocument {#3146
flag::STD_PROP_LIST: false,
flag::ARRAY_AS_PROPS: true,
iteratorClass: "ArrayIterator",
storage: [
"_id" => MongoDB\BSON\ObjectId {#3147
+"oid": "5dab14832d31e850ea1644b2",
},
"PlanTypeId" => "5daad2c12939b70f0b7ff052",
"Level" => "1",
],
},
],
},
],
我得到了Range,但是如何获得例如level-> Level?
<tr>
@foreach($allRanges as $d)
<td>{{$d['Range']}}</td>
</tr>
@endforeach