嗨,我想从集合中随机显示 6 行。每行作为时间戳,所以我可以使用它,但我的问题是如何从集合中只返回 6 行并使其随机
这是我收藏的一个示例 - 我使用 PHP
{
"age": "2",
"breed": "Bengal",
"dislikes": "Dislikes being patted by people",
"likes": "Like to purr and get headbutts. Sleeps on our bed, with Woody our dog, and also comes in for food at 6pm, loves Tin fish and is known to meow quite lo [...]",
"lost": true,
"pet_lost_date": NumberInt(1361366445),
"type": "cat"
}
我看到了这个 db.items.find().skip(randonNumberHere).limit(1); - MongoDB:从集合中提取多个随机文档
但我不明白,我从中了解到的只是 find() ,它找到了所有的 skip() ,它跳过了一些行,limit() 是返回的行数。
但是我的问题更多是关于获取所有丢失的宠物并将它们随机化并且只显示 6
public function lost_pets($no){
$collection = static::db()->ipet_mypet;
$pet = $collection->find(array('lost': true, '$where'=> function(){var randomNumber=Math.random(); return this.random>=randomNumber || this.random>randomNumber })).sort(array('pet_lost_date'=> 1)).limit(6);
}