gpt4 book ai didi

node.js - Node Mongo Native - 如何判断游标何时耗尽?

转载 作者:可可西里 更新时间:2023-11-01 09:09:06 26 4
gpt4 key购买 nike

node-mongo-native collection.find() function 的文档说它创建了一个游标对象,它延迟返回匹配的文档。此外:

The basic operation on a cursor is the nextObject method that fetches the next matching document from the database. The convenience methods each and toArray call nextObject until the cursor is exhausted.

不幸的是,文档没有提供如何判断游标何时实际耗尽的说明。您可以使用“toArray”方法并使用标准数组接口(interface)(例如“length”方法),但此解决方案不适用于传输大量数据。 MongoDB API Wiki 指的是 cursor.hasNext()在 mongo shell 中,但此方法在 node.js 驱动程序中似乎不可用。

在 node.js 中从 MongoDB 流式传输数据时,如何确定游标何时耗尽?

最佳答案

documentation对于 Cursor#nextObject 确实定义了如果没有更多可用结果,则其回调的第二个参数为 null

The first parameter will contain an error object on error while the second parameter will contain a document from the returned result or null if there are no more results.

关于node.js - Node Mongo Native - 如何判断游标何时耗尽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12826520/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com