Array( [id] => 00008 [game] => Array ( [0] => Array ( [gid] => 02569 [date] => 1363583244 ) [1] => Array ( [gid] => 04001 [date] => 1363339740 ) ) ) Array( [id] => 00010 [game] => Array ( [0] => Array ( [gid] => 02569 [date] => 1363583244 ) [1] => Array ( [gid] => 04028 [date] => 1363889740 ) ) )
上面是众多结果当中的2个。我现在的需求是从所有结果当中找到gid = 02569的,并且按照对应的date进行DESC排序
Similarly implemented using the aggregate framework (for reference only, not tested). Available with mongodb 2.2+.
What do you want to rank? The whole doc? Or doc.game? In other words, does it only look at the game level?
If you want to sort sub-documents, just use the aggregation framework. But an unwind should be added upstairs, and the key of sort is wrong, it should be game.date.
php’s aggregation framework documentation: http://www.php.net/manual/en/mongocollection.aggregate.php