PHP中的MongoDB游标,它是在查询执行时将所有记录带到客户端还是在游标迭代时将所有记录带到客户端?
我想用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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
此页面 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.
它对我有用..为了更多理解,请检查此链接。
谢谢@AdamComerford
It is working for me.. for more understanding check this link.
Thanks @AdamComerford