如何在新的mongodb PECL扩展中进行排序? [英] How does sorting work in the new mongodb PECL extension?

查看:44
本文介绍了如何在新的mongodb PECL扩展中进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从旧的Mongo扩展转到了最新的PHP驱动程序(mongodb).我也在使用为mongodb提供的PHP库.

I have just shifted from the old Mongo extension to the newest PHP driver (mongodb). I'm also using the PHP library provided for mongodb.

以前,我可以简单地在游标实例上执行->sort(),但是自从出现此错误以来,似乎不再是这种情况了:

Previously, I could simply do ->sort() on a cursor instance, but that doesn't seem to be the case any more since I get this error:

Fatal error: Uncaught Error: Call to undefined method MongoDB\Driver\Cursor::sort()

现在排序/限制/跳过的替代方法是什么?

What is the alternative to sorting/limiting/skipping now?

推荐答案

我在相应的 Github存储库中得到了有关此问题的答案.

为了能够与find进行排序,您简单使用第二个find参数,如下所示:

To be able to sort with find, you simply use the second find parameter like this:

$filter  = [];
$options = ['sort' => ['username' => 1]];

$client = new MongoDB\Client('mongodb://localhost');
$client->mydb->mycollection->find($filter, $options);

有关更多信息,请查看我在存储库中发布的问题:

For more information, look into the issue I have posted at the repository:

https://github.com/mongodb/mongo-php-driver/issues/214

这篇关于如何在新的mongodb PECL扩展中进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆