我正在通过 $push 在我的文档中的一个数组中进行“插入”,其中有一个字段日期,我想在使用 find() 时对其进行排序,但不对“_id”进行排序。如何按日期排序 (ordens.dtOrdem)?
<?php
$mongo = (new MongoDB\Client('mongodb://localhost:27017'))->Carteira;
$collection = $mongo->ativo;
/*First way that I've tried*/
$result1 = $collection->find([].['ordens' => ['sort' => ['dtOrdem' => -1]]]);
/*Second way that I've tried*/
$result2 = $collection->find([],['ordens' => ['each' => ['ordens' => ['sort' => ['dtOrdem' = -1]]]]]);
?>
字段“ordens.dtOrdem”未按降序排序。
PIPIONE
慕码人2483693
随时随地看视频慕课网APP