PHP中的MongoDB游标,它是在查询执行时将所有记录带到客户端还是在游标迭代时将所有记录带到客户端?

发布于 2025-01-07 19:33:23 字数 108 浏览 1 评论 0原文

我想用 MongoDB 优化我的查询,我想知道 PHP 客户端协议如何处理从 find() 查询返回的游标,它是否会将大块结果带到客户端或在某个位置获取单个记录从远程数据库获取时间并将其返回给应用程序?

I would like to optimize my queries with MongoDB, and I was wondering how does the PHP client protocol work with the cursor returning from find() query, does it bring large chunks of the results to the client side or fetches a single record at a time from the remote database and return it to the application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

后来的我们 2025-01-14 19:33:23

PHP 驱动程序(以及我遇到的任何其他驱动程序)将根据批量大小获取结果。如果您在 JS shell 中运行直接查找查询,您也可以看到这一点,它会在返回的前 20 个结果的末尾显示类似“has more”的内容。然后调用 iterate (it) 函数将加载下一个批次等。

在 PHP 中,批次大小是可配置的,最多可达返回数据大小总量的限制以及有关限制等的其他一些注意事项,如下所述:

http://php.net/manual/en/mongocursor.batchsize.php

The PHP driver (and any of the others I have run into) will fetch the results based on the batch size. You can also see this if you run a straight find query in the JS shell, it will say something like "has more" at the end of the first 20 results returned. Calling the iterate (it) function will then load the next batch etc.

In PHP the batch size is configurable, up to the limit on the total returned data size and some other caveats about limits etc. as described here:

http://php.net/manual/en/mongocursor.batchsize.php

甲如呢乙后呢 2025-01-14 19:33:23

此页面 https://www.php.net/manual/en/class。 mongocursor.php 暗示它是后者 - 游标对象不会一次性加载所有数据。但是,我看不到任何选项可以让您“调整”其执行速度。

This page https://www.php.net/manual/en/class.mongocursor.php hints that it is the latter - that the cursor object doesn't load all the data in one go. However, I can't see any option that would allow you to "tweak" the rate at which it does that.

落墨 2025-01-14 19:33:23

它对我有用..为了更多理解,请检查此链接。

$criteria = array( 'geo.loc' => array('$exists' => 1) );

$total    = $collection->count($criteria);

$response = $collection->find($criteria)->limit($total)->batchSize(100);

foreach($response as $value){
  $name = $value['name'];
}

谢谢@AdamComerford

It is working for me.. for more understanding check this link.

$criteria = array( 'geo.loc' => array('$exists' => 1) );

$total    = $collection->count($criteria);

$response = $collection->find($criteria)->limit($total)->batchSize(100);

foreach($response as $value){
  $name = $value['name'];
}

Thanks @AdamComerford

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文